0

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

有几种类型的游戏可以显示在第一个标签栏中,都是“CounterBase”的子类。当一个新游戏开始时,标签栏中的第一个视图控制器被换出。所有旋转代码都在 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;
}

历史库

-(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
4

1 回答 1

0

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

于 2013-03-30T14:42:51.177 回答