How to control the direction of screen rotation support in IOS 6

Source: Internet
Author: User
Tags bool versions

In iOS5.1 and previous versions, we used shouldautorotatetointerfaceorientation: to individually control the direction of a Uiviewcontroller's spin-screen support, such as:

-(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation    
{return    
    ( Interfaceorientation = = uiinterfaceorientationportrait);    
}

In iOS6, however, this method is discarded and is not used.

Shouldautorotatetointerfaceorientation:

Returns a Boolean value indicating whether the view controller supports the specified orientation. (Deprecated in IOS 6.0.) Override the Supportedinterfaceorientations andpreferredinterfaceorientationforpresentation methods instead.)

In practice, it will be found that the screen cannot be locked by supportedinterfaceorientations alone control.

-(Nsuinteger) supportedinterfaceorientations    
{return    
    uiinterfaceorientationmaskportrait;    
}

After several experiments to summarize the control of screen rotation support direction of the following methods:

Sub-class Uinavigationcontroller, adding methods

-(BOOL) shouldautorotate    
{return    
    self.topViewController.shouldAutorotate;    
}    
        
-(Nsuinteger) supportedinterfaceorientations    
{    
    return self.topViewController.supportedInterfaceOrientations;    
}

and set it as a program entry, or designate it as a Self.window.rootViewController

Then add your own view controller, if you want to disable the spin screen of a View controller: (Support for all versions of control)

-(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation    
{return    
    ( Interfaceorientation = = uiinterfaceorientationportrait);    
}    
        
-(BOOL) shouldautorotate    
{return    
    NO;    
}    
        
-(Nsuinteger) supportedinterfaceorientations    
{return    
    uiinterfaceorientationmaskportrait;    
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

If you want to turn on the full direction of a view controller, turn the screen support:

-(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation    
{return    
    ( Interfaceorientation!= uiinterfaceorientationportraitupsidedown);    
}    
        
-(Nsuinteger) supportedinterfaceorientations    
{return    
    uiinterfaceorientationmaskallbutupsidedown;    
}    
        
-(BOOL) shouldautorotate    
{return    
    YES;    
}

Thus, the individual control of each view controller is realized.

Incidentally, if all the view controller for the entire application does not support the spin screen, then simply:

-(Nsuinteger) Application: (UIApplication *) application Supportedinterfaceorientationsforwindow: (UIWindow *) window    
{return    
     uiinterfaceorientationmaskportrait;    
}

Next time, talk about IOS6 's memory control.

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.