Application is crashed due to InterfaceOrientation

2019-08-13 03:27发布

My application is Landscape based. The app crashes immediately when the app runs on my device.

I have selected these two fields

UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight

I am getting this error:

Terminating app due to uncaught exception UIApplicationInvalidInterfaceOrientation, reason: Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES

3条回答
老娘就宠你
2楼-- · 2019-08-13 03:43

Add shouldAutorotate and supportedInterfaceOrientations methods to your controller.

 -(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.

}
查看更多
太酷不给撩
3楼-- · 2019-08-13 03:45

You should use UIInterfaceOrientationMaskLandscape instead of UIInterfaceOrientationLandscapeLeft & UIInterfaceOrientationLandscapeRight. In iOS SDK 6.0+, new enum(UIInterfaceOrientationMask) is used for returning supported orientations.

查看更多
Rolldiameter
4楼-- · 2019-08-13 03:53

shouldAutorotateToInterfaceOrientation return only those with you want to support

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

please check one more thing, the connection between the File's Owner and View, if the view will not attach with the file's Owner It will crash.

查看更多
登录 后发表回答