iOS Development force individual Interface Vertical screen display

Source: Internet
Author: User
Method

1, through the Appdelegate-Application:supportedinterfaceorientationsforwindow: method to set

This method is to do, explain this method is used to set the interface to support the direction of the screen, is not used to turn the screen, this method does not meet part of the demand.

-(Uiinterfaceorientationmask) Application: (UIApplication *) application Supportedinterfaceorientationsforwindow: ( UIWindow *) Nowwindow {
    if (_deviceorientationportrait) {return
        uiinterfaceorientationmaskportrait;
    }
    return Uiinterfaceorientationmasklandscape | uiinterfaceorientationmaskportrait;
}

The _deviceorientationportrait is a bool attribute of the appdelegate when a vertical screen is required to display the interface:

In an interface, the following processing

-(void) Viewwillappear: (BOOL) animated {
    [Super viewwillappear:animated];

    [[Appdelegate delegate] setdeviceorientationportrait:yes];
}
-(void) Viewdiddisappear: (BOOL) animated {
    [Super viewdiddisappear:animated];

    [[Appdelegate delegate] setdeviceorientationportrait:no];
}

Note: This can only be set to the interface supported by the direction of the screen, if the initial access to the interface is the other direction, it can not guarantee the interface to turn back. If the entire project needs to be set up to the screen, it is good to use this method directly.

2, if you just enter the interface is to let the interface in the vertical screen, it is necessary to make a number of replication methods to deal with:

-(BOOL) shouldautorotate {return
    YES;
}
-(Uiinterfaceorientationmask) supportedinterfaceorientations {return
    uiinterfaceorientationmaskportrait;
}
-(uiinterfaceorientation) preferredinterfaceorientationforpresentation {
    return uiinterfaceorientationportrait;
}

This approach needs to be configured as follows, why:

3, the last

Uinavigationcontroller or Uitabbarcontroller, special treatment is required.

Whether to rotate automatically
-(BOOL) shouldautorotate{return
    self.topViewController.shouldAutorotate
}
Direction of support
-(uiinterfaceorientationmask) supportedinterfaceorientations{
    return self.topViewController.supportedInterfaceOrientations;
}
The first direction  is very important
-(uiinterfaceorientation) preferredinterfaceorientationforpresentation{
    return self.topViewController.preferredInterfaceOrientationForPresentation;
}

Recommended reading: Https://www.jianshu.com/p/6ac34ab1ea24 selective adoption.

Related Article

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.