iOS Screen Toggle Summary

Source: Internet
Author: User

    • Uiviewcontroller Force Vertical screen:

If you want the entire app vertical screen, you can write a Baseviewcontroller

1 First rewrite the following method in APPDELEGATE.M

-(uiinterfaceorientationmask) Application: (uiapplication *) application Supportedinterfaceorientationsforwindow: (uiwindow *) window

{

Back to the screen orientation you want to support, if only vertical screen is supported, directly return to vertical screen macro

}

2 in the Uiviewcontroller

-(void) Viewwillappear: (BOOL) animated{

Interfaceorientation defined for direction macros

[[uidevice currentdevice] setValue: [nsnumber numberwithinteger: Interfaceorientation] forkey:@ "orientation"];

}

    • Overall vertical screen, but the individual interface requires a horizontal screen

If there are individual interfaces in the interface that require a horizontal screen, you can add a flag to control the return value of the Supportedinterfaceorientationsforwindow, such as:

-(uiinterfaceorientationmask) Application: (uiapplication *) application Supportedinterfaceorientationsforwindow: (uiwindow *) window

{

if (! Self. Allowrotation) {

return uiinterfaceorientationmaskportrait;

}

return uiinterfaceorientationmasklandscaperight; // interface can only be rotated to the right

}

And then in the Uiviewcontroller code you need to cross-screen the following implementation: (Remember the horizontal screen flag bit value setting)

-(void) Viewwillappear: (BOOL) animated

{

[Super viewwillappear: animated];

[[uidevice currentdevice] setValue: [nsnumber numberwithinteger: Uiinterfaceorientationlandscaperight] forkey:@ "orientation"];

}

    • Compatibility issues

Preferredinterfaceorientationforpresentation This method is not the same as the definition of different iOS versions.

<IOS9:

-(nsuinteger) preferredinterfaceorientationforpresentation {

return uiinterfaceorientationportrait;

}

>=ios9

-(uiinterfaceorientationmask) supportedinterfaceorientations {

return uiinterfaceorientationmaskportrait;

}

Note If you override the Supportedinterfaceorientations method, there is a problem with switching from horizontal to vertical in the IOS7 version of the screen. I was rewriting it in Uiviewcontroler.

-(uiinterfaceorientationmask) supportedinterfaceorientations

Finally, in order to resolve the IOS7 version of the problem, you need to remove the rewrite as above.

Also note that the Interfaceorientation property inside the Uiviewcontroller is not recommended after IOS8.

iOS Screen Toggle Summary

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.