如何使 OpenGL ES 模板与工具栏自动旋转
几天来我一直在试图弄清楚如何做到这一点,但收效甚微。我已经设法手动处理 NSNotifications,它告诉我视图方向何时发生变化,然后我使用 CGAffineTransformations 将工具栏移动到正确的方向。这种方法可行,但不是很干净。所以我的问题是,如何将工具栏添加到 OpenGL-ES 视图并使其自动旋转?我认为这将涉及创建一个新的 viewController,然后将 OpenGL 视图和工具栏添加到该视图,但我没有足够的使用视图和子视图的经验来知道执行此操作的正确方法,或者即使这是正确的方法。我尝试这样做,但惨遭失败。
I've been trying to figure out how to do this for several days now with only limited success. I've managed to manually handle NSNotifications that tell me when the view orientation changes, then I use CGAffineTransformations to move my toolbar to the correct orientation. This kind of works, but isn't very clean. So my question is, how can I add a toolbar to the OpenGL-ES view and have it autorotate? I figure it will involve creating a new viewController, then adding the OpenGL view and toolbar to this view, but I don't have enough experience working with views and subviews to know the correct way to do this or even if this is the correct approach. I tried doing it and failed miserably.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我终于想通了。这不是很直观,但很有效。这个答案来自:http://www.idevgames.com/forums/thread-1773。 html
1) 添加新文件... Cocoa Touch Classes->UIViewController 子类,并将其命名为 GLViewController
2)在GLViewController.m中,在顶部添加#import "PaintingView.h",并在loadView方法中添加:,
再往下,进行修改:
3)在AppController.m中,添加#import "GLViewController.h"在顶部的 applicationDidFinishLaunching 中,添加以下内容:
您必须更改 GL 变换和触摸坐标以适应,但这将使您自动旋转。
希望这对我以外的其他人有帮助。
OK, I finally figured it out. It wasn't very intuitive, but it works. This answer came from: http://www.idevgames.com/forums/thread-1773.html
1) add new file... Cocoa Touch Classes->UIViewController subclass, and name it GLViewController
2) in GLViewController.m, add #import "PaintingView.h" at the top, and in the loadView method, add:
and further down, make a modification:
3) in AppController.m, add #import "GLViewController.h" at the top, and in applicationDidFinishLaunching, add this:
You'll have to change your GL transforms and touch coordinates to suit, but this'll get you autorotating.
Hope this is helpful to someone else besides myself.