在我的App Delegate中,我重寫了我的UITabBarController中的shouldAutorotateToInterfaceOrientation(不用擔心 - 我沒有繼承它! 。我這樣做是這樣的:iOS(iPhone/iPad)SDK - 如何從代碼中旋轉應用程序(與UITabBarController有關)
(AppDelegate.h底部):
@interface UITabBarController (MyApp)
@end
(AppDelegate.m底部):
@implementation UITabBarController (MyApp)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if(self.selectedIndex==4)
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
else
return (toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
目前,我有這樣,當我去到一個特定的選項卡(索引4),它不會旋轉到設備旋轉時的橫向(這是我想要的)。雖然問題是,如果應用程序已經是風景,並且您點擊該視圖,那就是風景(我希望它保持肖像)。 (注:該應用程序旋轉的罰款,如果我讓它,所以用shouldAutorotateToInterfaceOrientation
工作真的不應該解決這個問題(也可能))
我發現這個的UITabBarController委託方法:
- (void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)tabViewController {
NSUInteger indexOfTab = [theTabBarController.viewControllers indexOfObject:tabViewController];
if (indexOfTab == 4) {
//FILL GAP HERE!
}
}
我tryed這一點:
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
但它只能旋轉狀態欄 - 而不是整個應用程序。 UITabBarController中是否有一些方法(或其他)將它旋轉爲縱向來填充上面的空白?
對不起,如果它不是太混亂的人。
我試過了,但沒有奏效。看起來'shouldAutorotateToInterfaceOrientation'只在它要旋轉時被調用,而不是在它已經被旋轉時調用。 –