Ios5 在iOS 5和iOS 6上仅支持一个选项卡中的旋转

Ios5 在iOS 5和iOS 6上仅支持一个选项卡中的旋转,ios5,ios6,rotation,uitabbar,autorotate,Ios5,Ios6,Rotation,Uitabbar,Autorotate,我的应用程序是一个记分员,有两个标签。表一是记分实际发生的地方,表二包含过去比赛的历史记录。只有tab one支持旋转,旋转时隐藏其导航栏和选项卡栏(垂直空间不足)。我不想在历史选项卡上支持旋转,因为选项卡栏隐藏在计数器中。切换选项卡,然后让选项卡栏消失是非常不和谐的 有几种类型的游戏可能会显示在第一个选项卡栏中,所有这些都是“CounterBase”的子类。当一个新游戏开始时,选项卡栏中的第一个视图控制器被调出。所有旋转代码都是在CounterBase中处理的,而不是在其子类中处理的 我尝试过

我的应用程序是一个记分员,有两个标签。表一是记分实际发生的地方,表二包含过去比赛的历史记录。只有tab one支持旋转,旋转时隐藏其导航栏和选项卡栏(垂直空间不足)。我不想在历史选项卡上支持旋转,因为选项卡栏隐藏在计数器中。切换选项卡,然后让选项卡栏消失是非常不和谐的

有几种类型的游戏可能会显示在第一个选项卡栏中,所有这些都是“CounterBase”的子类。当一个新游戏开始时,选项卡栏中的第一个视图控制器被调出。所有旋转代码都是在CounterBase中处理的,而不是在其子类中处理的

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

我发现,在交换出第一个视图控制器后,不再调用app委托中SupportedInterfaceOrientionsForWindow

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

更新我忘了我正在使用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;
    }
反基地

- (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;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    BilliardsBuddyAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    return appDelegate.tabBarController.selectedIndex == 0;
}

-(BOOL)shouldAutorotate{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationPortrait;
}
- (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
历史基础

- (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;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    BilliardsBuddyAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    return appDelegate.tabBarController.selectedIndex == 0;
}

-(BOOL)shouldAutorotate{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationPortrait;
}
- (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
AppDelegate

- (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;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    BilliardsBuddyAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    return appDelegate.tabBarController.selectedIndex == 0;
}

-(BOOL)shouldAutorotate{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationPortrait;
}
- (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的《伟大》来展示一张行动单。显然,UIActionSheet不喜欢具有非UIViewController的委托集。(甚至可能是最顶层的视图控制器。我不确定。)从Tabbar切换回标准的UIActionSheet显示解决了这个问题