Application is crashed due to InterfaceOrientation

2019-08-13 03:50发布

问题:

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

回答1:

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.

}


回答2:

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.



回答3:

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