几天来,我一直试图弄清楚如何做到这一点,但收效甚微。我已经设法手动处理 NSNotifications,它告诉我视图方向何时发生变化,然后我使用 CGAffineTransformations 将我的工具栏移动到正确的方向。这种工作,但不是很干净。所以我的问题是,如何将工具栏添加到 OpenGL-ES 视图并让它自动旋转?我认为这将涉及创建一个新的 viewController,然后将 OpenGL 视图和工具栏添加到该视图中,但是我没有足够的使用视图和子视图的经验来知道执行此操作的正确方法,或者即使这是正确的方法. 我试过这样做,但失败了。
1 回答
2
好的,我终于想通了。这不是很直观,但它确实有效。这个答案来自: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)interfaceOrientation {
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 变换和触摸坐标以适应,但这会让你自动旋转。
希望这对我以外的其他人有所帮助。
于 2011-02-14T16:23:41.743 回答