由于InterfaceOrientation,应用程序崩溃

时间:2012-12-31 10:09:19

标签: iphone ios xcode uiinterfaceorientation

我的申请基于Landscape。当应用程序在我的设备上运行时,应用程序会立即崩溃。

我选择了这两个字段

UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight

我收到此错误:

  

由于未捕获的异常而终止应用   UIApplicationInvalidInterfaceOrientation,原因:支持   方向与应用程序没有共同的方向,并且   shouldAutorotate返回YES

3 个答案:

答案 0 :(得分:2)

向控制器添加 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.

}

答案 1 :(得分:0)

shouldAutorotateToInterfaceOrientation仅返回您想要支持的人

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}

请再检查一下,File's Owner and View之间的连接,如果视图不会附加到文件的所有者它会崩溃。

答案 2 :(得分:0)

您应该使用UIInterfaceOrientationMaskLandscape而不是UIInterfaceOrientationLandscapeLeft& UIInterfaceOrientationLandscapeRight。在iOS SDK 6.0+中,新的枚举(UIInterfaceOrientationMask)用于返回支持的方向。

相关问题