应用程序由于InterfaceOrientation而崩溃
我的应用程序是基于Landscape
。 应用在我的设备上运行时,该应用立即崩溃。
我select了这两个领域
UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight
我得到这个错误:
由于未捕获exception而终止应用程序UIApplicationInvalidInterfaceOrientation,原因:支持的方向与应用程序没有共同的方向,并且shouldAutorotate返回YES
将shouldAutorotate和supportedInterfaceOrientations方法添加到您的控制器。
-(BOOL)shouldAutorotate { return YES; //this will auto-rotate the orientation. } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; // will force the app to load in landscape, you can change it as per your need. }
shouldAutorotateToInterfaceOrientation只返回你想要支持的那些
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)); }
请检查一个东西, File's Owner and View
之间的连接,如果视图不会附加文件的所有者将崩溃。
您应该使用UIInterfaceOrientationMaskLandscape而不是UIInterfaceOrientationLandscapeLeft和UIInterfaceOrientationLandscapeRight。 在iOS SDK 6.0+中,新枚举(UIInterfaceOrientationMask)用于返回支持的方向。