如何使用工具栏自动旋转制作OpenGL ES模板

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

要回复问题请先登录注册