preferredInterfaceOrientationForPresentation must return a supported interface orientation (iOS 6)

北慕城南 提交于 2019-12-10 15:33:59

问题


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];
}

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!'

Why am I getting this error?


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.


回答1:


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

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

Return Value

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.



来源:https://stackoverflow.com/questions/13689474/preferredinterfaceorientationforpresentation-must-return-a-supported-interface-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!