IOS _ screen orientation supported by mobile phones
The settings support two levels of screen orientation: app-level and viewController-level.
You can set the app level in [target]-[general]-[device orientation], for example:
By default, Upside Down is not selected, and others are selected.
(Why is Upside Down not recommended? Because the iPhone phone app does not support Upside Down. If your app supports Upside Down, if the user Upside goes Down when using your app, the call screen will be reversed and the user experience will be poor. We do not recommend you select Upside Down for Apple, which has always paid attention to user experience)
The viewController level is set in each viewController.
Note that viewController settings are restricted by app-level settings, that is, viewController can only set one or more screen directions at the app level, it cannot be set if it is not selected. For example, if the Upside Down option is not selected, viewController cannot set the Upside Down direction.
How can I set the screen direction in viewController?
Before iOS6:
// Set the screen to only vertical-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) interfaceOrientation {return (interfaceOrientation = UIInterfaceOrientationPortrait );}
Since iOS6, the above method has been abandoned and there are three new methods:
// Does not support screen rotation-(BOOL) shouldAutorotate {return NO;} // only supports vertical-(NSUInteger) supportedInterfaceOrientations {return UIInterfaceOrientationPortrait ;} // The screen is loaded vertically at the beginning. //-(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {// return UIInterfaceOrientationPortrait ;//}
If the versions earlier than iOS6 correspond to each other, the discarded method also needs to be added.
However, at the beginning of iOS8.3, In the viewController with UIAlertView, the pop-up UIAlertView will crash. The Log information is as follows:
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [_UIAlertShimPresentingViewController shouldAutorotate] is returning YES'
After reading the official documentation, we found that the supportedInterfaceOrientations method returned values of the UIInterfaceOrientationMask type, so we should use UIInterfaceOrientationMaskPortrait. The UIInterfaceOrientationMask type is available from iOS6, but only iOS8.3 will crash.
As for the preferredInterfaceOrientationForPresentation method, the returned value is still of the old UIInterfaceOrientation type.