2011-02-05 23 views
1

我一直在试图找出如何做到这一点,现在只有有限的成功。我设法手动处理NSNotifications,告诉我视图方向何时更改,然后使用CGAffineTransformations将我的工具栏移动到正确的方向。这种作品,但不是很干净。所以我的问题是,我该如何添加一个工具栏到OpenGL-ES视图并让它自动旋转?我认为这将涉及到创建一个新的viewController,然后将OpenGL视图和工具栏添加到该视图,但是我没有足够的经验来处理视图和子视图以了解正确的方式来执行此操作,或者即使这是正确的方法。我尝试过并且失败惨败。如何使工具栏自动旋转的OpenGL ES模板

回答

2

好的,我终于明白了。这不是很直观,但它的工作原理。这个答案来自:http://www.idevgames.com/forums/thread-1773.html

1)添加新的文件......可可触摸类 - > UIViewController子类,并将其命名为GLViewController 2)GLViewController.m,在顶部添加#进口“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)]; 

和进一步向下,进行修改:在AppController.m

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

3),在顶部加入#进口 “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变换和触摸坐标以适应,但这会让您自动旋转。

希望这对除了我自己以外的其他人有帮助。