iOS screen set vertical screen, individual interface force horizontal screen

Source: Internet
Author: User

Project needs, only one interface needs horizontal screen display, the other all only support vertical screen display can, online data many, but tried all not good, and finally found because my project Uiviewcontroller outer layer is Uinavigationveiwcontroller, It is not possible to overload supportedinterfaceorientations and Shouldautorotate methods only in Uiviewcontroller.

The following is a description of the setup steps: (Reference http://www.cocoachina.com/bbs/read.php?tid-244095.html)

Step 1: Set the supported interface orientations for all supported orientations in Info.plist, I set this up:

    

Step 2: Add attributes to the custom Navigationviewcontroller:

@property (nonatomic, assign) BOOL Supportlandscape;

Initialization

 

-(ID) init{if (self = [super init]) {[Self setup];} return self;} -(void) setup{//other settings        ...    Self.supportlandscape = NO;}

  

Overloaded Supportedinterfaceorientations Method:

-(Uiinterfaceorientationmask) Navigationcontrollersupportedinterfaceorientations: (UINavigationController *) navigationcontroller{    if (self.supportlandscape) {        return uiinterfaceorientationmaskportrait | Uiinterfaceorientationmasklandscaperight;    } else{        return uiinterfaceorientationmaskportrait;}    }

Step 3: All Viewcontroller in my project are controlled by Navigationcontroller, so just set it up in a viewcontroller that needs to support a horizontal screen:

-(void) Viewdidappear: (BOOL) animated{    [Slidenavigationcontroller sharedinstance].supportlandscape = YES;} -(void) Viewdiddisappear: (BOOL) animated{    [Slidenavigationcontroller sharedinstance].supportlandscape = NO;}

Pro-Test Use ~

iOS screen set vertical screen, individual interface force horizontal screen

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.