ios preferredInterfaceOrientationForPresentation 必须返回受支持的界面方向
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12690963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
preferredInterfaceOrientationForPresentation must return a supported interface orientation
提问by Peter Lapisu
This error doesn't make sense, as the preferred orientation UIInterfaceOrientationLandscapeRight
is returned by the supported orientation
这个错误没有意义,因为首选方向UIInterfaceOrientationLandscapeRight
是由支持的方向返回的
//iOS6
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft);
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
Error :
错误 :
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'
由于未捕获的异常“UIApplicationInvalidInterfaceOrientation”而终止应用程序,原因:“preferredInterfaceOrientationForPresentation 必须返回受支持的界面方向!”
回答by lms
Your code should look like this:
您的代码应如下所示:
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
Also, make sure in your Info.plist
you have set the correct orientations for you app because what you return from supportedInterfaceOrientations
is intersected with the Info.plist
and if it can't find a common one then you'll get that error.
此外,请确保您Info.plist
的应用程式,你因为你从回报你已经设置了正确的方向supportedInterfaceOrientations
与相交的Info.plist
,如果它不能找到一个常见的一种,那么你会得到错误。
回答by coco
supportedInterfaceOrientations is only called, if shouldAutorotate is set to YES
仅当 shouldAutorotate 设置为 YES 时才调用 supportedInterfaceOrientations
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
The easiest approach for me, is only to set the Info.plist
对我来说最简单的方法就是设置 Info.plist
If you like to support iOS 5 use this code in your view controllers.
如果您想支持 iOS 5,请在您的视图控制器中使用此代码。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
回答by borrrden
Those are the wrong enums for supportedInterfaceOrientations
. You need to use UIInterfaceOrientationMaskLandscapeLeft
, etc (note the word maskin the middle)
这些是错误的枚举supportedInterfaceOrientations
。您需要使用UIInterfaceOrientationMaskLandscapeLeft
等(注意中间的字掩码)
回答by Panayotis
from the documentation:
从文档:
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}
Note that the correct orientation is "Mask"! Did you try this?
请注意,正确的方向是“蒙版”!你试过这个吗?