preferredInterfaceOrientationForPresentation必须返回支持的接口方向
此错误没有任何意义,因为支持的方向返回首选方向UIInterfaceOrientationLandscapeRight
//iOS6 -(BOOL)shouldAutorotate { return NO; } -(NSUInteger)supportedInterfaceOrientations { return (UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft); } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; }
错误:
由于未捕获exception“UIApplicationInvalidInterfaceOrientation”而终止应用程序,原因是:“preferredInterfaceOrientationForPresentation必须返回支持的界面方向!
你的代码应该是这样的:
-(BOOL)shouldAutorotate { return NO; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; }
另外,请确保在您的Info.plist
为您的应用程序设置了正确的方向,因为您从supportedInterfaceOrientations
返回的信息与Info.plist
相交,如果找不到通用信息,那么您将得到该错误。
只有当shouldAutorotate设置为YES时,才会调用supportedInterfaceOrientations
- (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; }
对我来说最简单的方法就是设置Info.plist
如果您想支持iOS 5,请在您的视图控制器中使用此代码。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return UIInterfaceOrientationIsLandscape(interfaceOrientation); }
这些是supportedInterfaceOrientations
的错误枚举。 你需要使用UIInterfaceOrientationMaskLandscapeLeft
等( 注意中间的单词掩码 )
从文档:
-(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft; }
请注意,正确的方向是“面具”! 你试过这个吗?