【问题标题】:Autorotate ignored when changing tabs更改选项卡时忽略自动旋转
【发布时间】:2011-03-14 16:16:20
【问题描述】:

我有一个带有 UITabBarController 的应用程序,每个选项卡都有一个 UINavigationController “附加”到它。现在让我们假设选项卡 1,2 和 4 中的 rootViewControllers(navigationControllers)仅支持纵向方向,并且具有这样的“shouldAutorotateToInterfaceOrientation”实现,仅在被要求旋转到纵向时才返回 YES。然而,Tab 3 在其 navigationController 中有一些 viewControllers 支持横向。

当我现在在选项卡 3 中并移动到支持横向的视图控制器之一时,我能够转动设备并且界面变为横向。然而,如果我在横向模式下使用界面点击选项卡 1、2 或 4,界面不会变回纵向而是保持横向,尽管显示的 viewController 显然只支持纵向。

我不确定我缺少什么或者这是否是预期的行为,一旦我通过 tabBarController 切换到仅纵向视图控制器,我希望界面方向切换回纵向。整个层次结构都是以编程方式构建的。

谢谢!

【问题讨论】:

    标签: iphone uitabbarcontroller orientation autorotate


    【解决方案1】:

    在我的一个应用程序中,我遇到了与您相同的问题,不同之处在于我没有在选项卡项中使用导航控制器。

    我最终为方法 shouldAutorotate 为 UITabBarController 创建了一个类别(因为它不应该被子类化)...

    @implementation UITabBarController (orientation)
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    #if DEBUG 
        NSLog(@"UITabBarController (orientation) -> shouldAutorotateToInterfaceOrientation: [%d]",toInterfaceOrientation);
    #endif  
        //if(toInterfaceOrientation == UIInterfaceOrientationPortrait) return YES;
    //  else return [self.selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
        if (self.selectedViewController == [self.viewControllers objectAtIndex:kLibraryStoreTabIndex])
            return NO;
    
    
        if( self.selectedViewController == [self.viewControllers objectAtIndex:kContactTabIndex]){
    
            return YES;
        }
    // rest of the conditions depending of the tab 
    
    return NO; //last option 
    }
    

    【讨论】:

    • 嗯,我刚刚做了一些测试,并且在不转动设备的情况下切换选项卡时,我的 shouldAutorotateToInterfaceOrientation 类别中的方法没有被调用(这是有道理的)。你手动调用它吗?
    猜你喜欢
    • 2011-08-06
    • 1970-01-01
    • 2023-03-18
    • 2012-08-12
    • 2016-01-12
    • 1970-01-01
    • 1970-01-01
    • 2020-05-06
    • 1970-01-01
    相关资源
    最近更新 更多