There are two levels of supported screen orientations, one at the app level and the other at the Viewcontroller level.
App-level settings can be set in [Target]-[general]-[device orientation], such as:
By default, upside down is not checked, and the others are checked.
(Why upside down is not recommended, because the iphone phone app is not supported upside down, if your app supports upside down, in case users in your app upside down, this time to call, You will see the entire call screen is reversed, the user experience is not good. Always focus on the user experience of the Apple is not recommended you tick upside down)
The Viewcontroller level is set in each viewcontroller.
One thing to note here is that the Viewcontroller settings are limited by app-level settings-that is, the screen orientation that Viewcontroller can set can only be one or more of the options that are checked at the app level, and not checked for settings. For example, the above upside down is not checked, then Viewcontroller can not set the direction of upside down.
So how do you set the screen orientation in Viewcontroller?
IOS6 before:
The Setup screen supports only vertical-(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation{ return (interfaceorientation = = uiinterfaceorientationportrait);}
From IOS6 onwards, the above method has been discarded, with 3 new methods:
Screen rotation not supported-(BOOL) shouldautorotate{ return no;} Supports only vertical-(Nsuinteger) supportedinterfaceorientations{ return uiinterfaceorientationportrait;} When the screen starts loading, it is vertical//-(Uiinterfaceorientation) preferredinterfaceorientationforpresentation {// return uiinterfaceorientationportrait;//}
If the previous version of IOS6 also corresponds, then the discarded method also needs to be added up.
However, iOS8.3 start, in the Uialertview viewcontroller inside, pop Uialertview will crash, log information as follows:
Terminating app due to uncaught exception ' uiapplicationinvalidinterfaceorientation ', Reason: ' Supported orientations Have no common orientation with the application, and [_uialertshimpresentingviewcontroller Shouldautorotate] is returning Y ES '
By reviewing the official documentation, it was found that the return value of the Supportedinterfaceorientations method is of type Uiinterfaceorientationmask, So we should use uiinterfaceorientationmaskportrait. The Uiinterfaceorientationmask type is from iOS6, but only until iOS8.3 collapses.
As for the Preferredinterfaceorientationforpresentation method, the return value is still the old uiinterfaceorientation type.
Ios_ about the screen orientation supported by the phone