如何使 OpenGL ES 模板与工具栏自动旋转

发布于 2024-10-16 04:31:27 字数 279 浏览 2 评论 0原文

几天来我一直在试图弄清楚如何做到这一点,但收效甚微。我已经设法手动处理 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甩你一脸翔 2024-10-23 04:31:27

好吧,我终于想通了。这不是很直观,但很有效。这个答案来自:http://www.idevgames.com/forums/thread-1773。 html

1) 添加新文件... Cocoa Touch Classes->UIViewController 子类,并将其命名为 GLViewController
2)在GLViewController.m中,在顶部添加#import "PaintingView.h",并在loadView方法中添加:,

CGRect    rect = [[UIScreen mainScreen] applicationFrame];
self.view = [[PaintingView alloc] initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)];

再往下,进行修改:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOr​ientation {
    return YES;
}

3)在AppController.m中,添加#import "GLViewController.h"在顶部的 applicationDidFinishLaunching 中,添加以下内容:

GLViewController *viewController = [[GLViewController alloc] init];
UIToolbar *mainTools = [UIToolbar new];
mainTools.frame = CGRectMake(0, 0, 300, 50);
UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithTitle:@"Help!" style:UIBarButtonItemStyleBordered target:self action:nil];
[mainTools setItems:[NSArray arrayWithObjects:newButton, nil]];
[[viewController view] addSubview:mainTools];
[window addSubview:[viewController view]];

您必须更改 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:

CGRect    rect = [[UIScreen mainScreen] applicationFrame];
self.view = [[PaintingView alloc] initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)];

and further down, make a modification:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOr​ientation {
    return YES;
}

3) in AppController.m, add #import "GLViewController.h" at the top, and in applicationDidFinishLaunching, add this:

GLViewController *viewController = [[GLViewController alloc] init];
UIToolbar *mainTools = [UIToolbar new];
mainTools.frame = CGRectMake(0, 0, 300, 50);
UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithTitle:@"Help!" style:UIBarButtonItemStyleBordered target:self action:nil];
[mainTools setItems:[NSArray arrayWithObjects:newButton, nil]];
[[viewController view] addSubview:mainTools];
[window addSubview:[viewController view]];

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文