preferredInterfaceOrientationForPresentation必须返回支持的接口方向(iOS 6) [英] preferredInterfaceOrientationForPresentation must return a supported interface orientation (iOS 6)

查看:884
本文介绍了preferredInterfaceOrientationForPresentation必须返回支持的接口方向(iOS 6)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序窗口的根视图控制器是一个子类UINavigationController。我已将此代码添加到课程中:

My application window's root view controller is a subclassed UINavigationController. I have added this code to the class:

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

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

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

在我的根UIViewController中,我添加了以下代码:

In my root UIViewController I have added this code:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait;
}

当设备在此视图控制器上旋转为横向时,我呈现模态查看控制器。当设备旋转回肖像时,我应该关闭模态视图,但是当我这样做时会出现以下错误:

When the device is rotated to landscape on this view controller, I present a modal view controller. When the device is rotated back to portrait, I am supposed to dismiss the modal view, but when I do I get the following error:

'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'

为什么我收到此错误?

我尝试从根UIViewController中的shouldAutorotate返回YES,现在我收到错误'支持的方向没有共同的方向应用程序,并且shouldAutorotate返回YES'。这是没有意义的我,因为UIInterfaceOrientationPortrait是支撑取向的一个应用程序

I tried returning YES from shouldAutorotate in the root UIViewController, and now I get the error 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'. This makes no sense to my, because UIInterfaceOrientationPortrait is one of the applications supported orientations.

推荐答案

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

In -supportedInterfaceOrientations, you need to return values from UIInterfaceOrientationMask, not UIInterfaceOrientation. In particular, it looks like you want UIInterfaceOrientationMaskPortrait

下面是什么-supportedInterfaceOrientations的文件说,对返回值:

Here's what the documentation for -supportedInterfaceOrientations says about the return value:


返回值

指定位掩码支持哪些方向。有关有效的位掩码值,请参见UIInterfaceOrientationMask。此方法返回的值不得为0.

A bit mask specifying which orientations are supported. See "UIInterfaceOrientationMask" for valid bit-mask values. The value returned by this method must not be 0.

这篇关于preferredInterfaceOrientationForPresentation必须返回支持的接口方向(iOS 6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆