1

我有一个 UINavigationController,它的根 UIViewController 只支持纵向。当用户按下按钮时,第二个 UIViewController 被加载并推送到堆栈上,这个视图控制器,我们称之为 secondViewController,只支持横向。

通常会发生的情况是界面在转换到 secondViewController 期间旋转,但尽管 shouldAutorotateToInterfaceOrientation: 在 secondViewController 上被调用,但不会发生这种情况。一旦我在显示 secondViewController 时手动倾斜设备,它就会按预期旋转,当切换回第一个 UIViewController 时,它会按原样旋转回纵向。

为了测试第一个 UIViewController 允许的界面方向是否对进程有任何影响,我设置了一个 return YES;但是,对于那里的所有接口,问题仍然存在。我还阅读了有关该主题的技术问答,但根据此文档,一切都应该没问题,UINavigationController 是窗口的唯一子视图。

我完全以编程方式创建了 secondViewController(覆盖了 loadView),并且之前在其他应用程序中使用过这种特殊情况。有人知道我可能做错了什么吗?

4

1 回答 1

1

Apparently the change doesn't happen automatically, the following gives the neccessary "push":

- (void) viewWillAppear:(BOOL)animated {
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
于 2011-04-23T09:21:52.970 回答