2011-02-14 85 views
2

我有一個應用程序與我想檢測界面方向的一個tabbar。應用程序不改變方向

我已經在info.plist中設置了支持的方向。 這是我的主界面聲明:

@interface MyAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> { 
    ... 
} 

這是MyAppDelegate執行:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
     return NO; 
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
     return YES; 
    if (interfaceOrientation == UIInterfaceOrientationPortrait) 
     return YES; 
    if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
     return NO; 
    } 

,並在我試圖檢測取向變化必要的看法,我打電話這些方法:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation; 

我已經在這些方法中設置NSLog打印,他們都沒有註冊任何更改。甚至沒有在shouldAutorotateToInterfaceOrientation方法中。

任何人都可以幫我嗎?我在做什麼錯了? 任何幫助將不勝感激。

回答

5

shouldAutorotateToInterfaceOrientation:是您必須在視圖控制器中實現的方法,而不是在您的應用程序委託中實現。要使標籤欄應用程序旋轉,標籤欄控制器的所有子控件都必須返回YES以獲取所需的界面方向。

同樣,willRotateToInterfaceOrientation:didRotateFromInterfaceOrientation:都在視圖控制器來實現,而不是在視圖,你說你做

+0

謝謝你,奧雷Begemann。應該在所有視圖控制器中實現shouldAutorotateToInterfaceOrientation方法,以使方向工作。我得到了它的工作。但現在問題是所有的選項卡都在旋轉(我有3個),我只需要旋轉第二個。 如果你幫我這個,你有啤酒:) 無論如何,再次感謝。幫助我很多! – Cornholio 2011-02-15 09:42:39

1
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

方法在您的viewController中實現,而不是在的appdelegate