iOS6 从横屏模式切换到竖屏模式的旋转问题

5

我正在使用iOS 6的新方向方法,它运行良好。我的视图在竖屏模式下呈现,当我呈现viewcotrnoller并将其旋转到横屏时,关闭该viewcontroller后它会恢复方向。这意味着它应该保持在横屏状态,但它变成了竖屏状态。

以下是我的代码:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;

}

// Tell the system It should autorotate
- (BOOL) shouldAutorotate {
    return YES;
}

// Tell the system which initial orientation we want to have
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationMaskPortrait;
}

我认为这是由于preferredInterfaceOrientationForPresentation方法引起的,但是我没有找到解决方法。请帮忙!谢谢!

具体问题是什么?您已将preferredInterfaceOrientation设置为仅纵向。因此,我猜控制器应该始终只以纵向模式呈现。尝试使用UIInterfaceOrientationMaskAll并查看发生了什么。 - mayuur
由于未捕获的异常'UIApplicationInvalidInterfaceOrientation',应用程序终止,原因是'preferredInterfaceOrientationForPresentation必须返回支持的界面方向!'它崩溃了。 - iProgrammer
2
我的错。它接受的是UIInterfaceOrientation而不是Mask。顺便说一下,删除这个方法是有效的!反正有什么用呢? - mayuur
谢谢你的评论:“删除这个方法可行!”它刚刚救了我的命! - Emre Akman
如何在iOS6中支持一个应用程序的多个方向:https://dev59.com/BGnWa4cB1Zd3GeqPyDMc#13881884 - Hox
显示剩余2条评论
1个回答

6
如果您希望在开始时支持所有界面方向,请不要编写preferredInterfaceOrientationForPresentation方法,因为它将始终采用该首选界面方向。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接