preferredInterfaceOrientationForPresentation必须返回支持的界面方向(iOS 6)

4

我的应用程序窗口的根视图控制器是一个子类化的UINavigationController。我已经在该类中添加了以下代码:

- (BOOL)shouldAutorotate
{
    return [self.topViewController shouldAutorotate];
}

- (NSUInteger)supportedInterfaceOrientations
{
    return [self.topViewController supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.topViewController preferredInterfaceOrientationForPresentation];
}

在我的根UIViewController中,我添加了以下代码:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait;
}

当设备在这个视图控制器上旋转到横向时,我会呈现一个模态视图控制器。当设备旋转回纵向时,我应该关闭模态视图,但这样做时,我会得到以下错误:

'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'

为什么会出现这个错误?


我尝试在根UIViewController中从shouldAutorotate返回YES,现在我收到错误信息:“支持的方向与应用程序没有共同的方向,并且shouldAutorotate正在返回YES”。这对我来说毫无意义,因为UIInterfaceOrientationPortrait是应用程序支持的方向之一。

1个回答

14
-supportedInterfaceOrientations 中,你需要返回来自 UIInterfaceOrientationMask 而不是 UIInterfaceOrientation 的值。特别地,你可能想要使用 UIInterfaceOrientationMaskPortrait
下面是关于 -supportedInterfaceOrientations 返回值的文档:

返回值

一个位掩码,指定支持的方向。查看“UIInterfaceOrientationMask”以获取有效的位掩码值。此方法返回的值不能为 0。


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