我的应用程序窗口的根视图控制器是 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 是应用程序支持的方向之一。
In -supportedInterfaceOrientations
,您需要从返回值UIInterfaceOrientationMask
, not UIInterfaceOrientation
。特别是,它看起来像你想要的UIInterfaceOrientationMaskPortrait
以下是 -supportedInterfaceOrientations 的文档关于返回值的说明:
返回值
指定支持哪些方向的位掩码。有关有效的位掩码值,请参阅“UIInterfaceOrientationMask”。该方法返回的值不能为0。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)