2011-02-05 111 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變換和觸摸座標以適應,但這會讓您自動旋轉。

希望這對除了我自己以外的其他人有幫助。