iOS 5和6只支持一个选项卡旋转

问题描述:

我的应用程序是一个有两个选项卡的记分员。选项卡一是实际进行记分的地方,选项卡二包含过去的比赛历史。只有一个标签支持旋转,并且在旋转时隐藏它的导航和标签栏(没有足够的垂直空间)。我不想在历史记录选项卡上支持旋转,因为tabbar被隐藏在计数器中。切换选项卡然后让选项卡消失是相当困难的。iOS 5和6只支持一个选项卡旋转

在第一个标签栏中可能会显示几种类型的游戏,即“CounterBase”的所有子类。当新游戏启动时,tabbar中的第一个视图控制器被换出。所有循环代码都在CounterBase中处理,而不是在其子类中处理。

我试过很多东西来支持旋转,但它们都是片状的。目前为止我得到的最好结果是在第一次加载应用程序时让一切正常工作,但是在第一次启动新游戏时交换停止(交换第一个视图控制器)。

我发现的一件事是在第一个视图控制器被换出之后,应用程序委托中的supportedInterfaceOrientationsForWindow不再被调用。

处理这个问题的最佳方法是什么?

更新我忘了我在iPad上使用标签栏,因为它总是隐藏。旋转在那里工作得很好,所以现在我倍加困惑。但是,历史选项卡从不显示,这可能相关也可能不相关。

更新2我也尝试使用自定义导航控制器并实现shouldAutorotate。仍然没有工作。

更新3我发现它并没有替换导致问题的第一个选项卡,而是在带有presentViewController的导航控制器中呈现模态视图:animated:completion :.我曾尝试在呈现的视图控制器中覆盖shouldAutorotate,但它什么也不做。另外,我在下面的UINavigationController中添加了我正在使用的类别。

这是我目前的执行:

标签栏控制器类

-(BOOL)shouldAutorotate{ 
     if (self.selectedIndex == 0) // First tab is Counter 
      return YES; 
     else 
      return NO; 
    } 

    - (NSUInteger)supportedInterfaceOrientations{ 
     if (self.selectedIndex==0) { 
      return UIInterfaceOrientationMaskAll; 
     } 
     else { 
      return UIInterfaceOrientationMaskAllButUpsideDown; 
     } 
    } 

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
     ALog(@"Tab bar selectedIndex: %d", self.selectedIndex); 
     return self.selectedIndex == 0; 
    } 

CounterBase

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    if (UI_USER_INTERFACE_IDIOM_PAD()){ 
     return YES; 
    } else if (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown){ 
     return YES; 
    } 
    return NO; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    if (UI_USER_INTERFACE_IDIOM_PHONE()) 
     return UIInterfaceOrientationMaskAllButUpsideDown; 
    else 
     return UIInterfaceOrientationMaskAll; 
} 

- (BOOL) shouldAutorotate { 
    return YES; 
} 

HistoryBase

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ 
    BilliardsBuddyAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; 
    return appDelegate.tabBarController.selectedIndex == 0; 
} 

-(BOOL)shouldAutorotate{ 
    return NO; 
} 

-(NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationPortrait; 
} 

的AppDelegate

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { 
    ALog(@"Tab bar selectedIndex: %d", tabBarController.selectedIndex); 
    if (tabBarController.selectedIndex == 0 || UI_USER_INTERFACE_IDIOM_PAD()){ 
     return UIInterfaceOrientationMaskAll; 
    } else { 
     return UIInterfaceOrientationMaskPortrait; 
    } 
} 


@implementation UINavigationController (autoRotate) 
-(BOOL)shouldAutorotate { 
    return YES; 
} 
- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskAll; 
} 
@end 

好了,三天后我终于解决了这个。我正在使用Mugunth Kumar伟大的UIKit categories来呈现一个动作表。显然UIActionSheet不喜欢有一个不是UIViewController的委托集。 (或者甚至可能是最顶层的视图控制器,我不确定。)切换回标准的UIActionSheet showFromTabBar解决了这个问题。