【问题标题】:preferredInterfaceOrientationForPresentation must return a supported interface orientation (iOS 6)preferredInterfaceOrientationForPresentation 必须返回受支持的界面方向 (iOS 6)
【发布时间】:2012-12-03 18:32:58
【问题描述】:

我的应用程序窗口的根视图控制器是一个子类 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 是应用程序支持的方向之一。

【问题讨论】:

    标签: ios uiviewcontroller ios6 autorotate


    【解决方案1】:

    -supportedInterfaceOrientations 中,您需要从UIInterfaceOrientationMask 返回值,而不是UIInterfaceOrientation。特别是,看起来你想要UIInterfaceOrientationMaskPortrait

    以下是 -supportedInterfaceOrientations 的文档中关于返回值的说明:

    返回值

    指定支持哪些方向的位掩码。有关有效的位掩码值,请参阅“UIInterfaceOrientationMask”。该方法返回的值不能为0。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-23
      • 2011-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-03
      • 1970-01-01
      • 2013-05-04
      相关资源
      最近更新 更多