Ios_ about the screen orientation supported by the phone

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.