pushViewController: - 当设备处于横向模式时,如何以仅纵向模式显示?

时间:2011-02-16 14:43:43

标签: iphone sdk uiviewcontroller orientation pushviewcontroller

我有2个视图控制器,root和detail。根视图控制器支持横向和纵向,因此它具有以下代码:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return (interfaceOrientation == UIInterfaceOrientationPortrait
        || interfaceOrientation == UIInterfaceOrientationLandscapeLeft
        || interfaceOrientation == UIInterfaceOrientationLandscapeRight
        || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
    }

以上代码适用于根视图控制器。

如果正在显示根视图控制器,并且用户将设备旋转为横向模式,则视图会相应地进行调整。从这一点来说,如果将我的详细视图控制器推入堆栈,它将以横向模式加载。但是,它不应该,因为我已将其配置为仅支持纵向模式。我在我的详细视图控制器中使用下面的代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

1 个答案:

答案 0 :(得分:0)

在第二个视图控制器中,将代码替换为...

return UIInterfaceOrientationIsPortrait( interfaceOrientation );