IOS6 control technique of rotary screen

Source: Internet
Author: User

In iOS5.1 and previous versions, we typically use shouldautorotatetointerfaceorientation: to individually control the spin-screen direction support for a uiviewcontroller, such as:

    1. -(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation
    2. {
    3. return (interfaceorientation = = uiinterfaceorientationportrait);
    4. }



In iOS6, however, this method is deprecated 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 is found that the screen cannot be locked by a separate control via the supportedinterfaceorientations .

    1. -(Nsuinteger) supportedinterfaceorientations
    2. {
    3. return uiinterfaceorientationmaskportrait;
    4. }



After many experiments, the following methods are summarized to control the direction of the screen rotation support:

Subclass Uinavigationcontroller, adding methods

    1. -(BOOL) shouldautorotate
    2. {
    3. return self.topViewController.shouldAutorotate;
    4. }
    5. -(Nsuinteger) supportedinterfaceorientations
    6. {
    7. return self.topViewController.supportedInterfaceOrientations;
    8. }


and set it as the entry for the program, or designated as Self.window.rootViewController

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

 

    1. -  (bool) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation  
    2. {  
    3.     return  ( interfaceorientation == uiinterfaceorientationportrait);   
    4. }  
    5.   
    6. -(bool) shouldautorotate  
    7. {  
    8.     return no;   
    9. }  
    10.   
    11. -(Nsuinteger) supportedinterfaceorientations  
    12. {  
    13.     < span class= "keyword" >return uiinterfaceorientationmaskportrait;  
    14. }  

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

    1. -  (bool) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation  
    2. {  
    3.     return  ( Interfaceorientation != uiinterfaceorientationportraitupsidedown);   
    4. }   
    5. &NBSP;&NBSP;
    6. -(Nsuinteger) supportedinterfaceorientations  
    7. {&NBSP;&NBSP;
    8.     return  uiinterfaceorientationmaskallbutupsidedown;  
    9. }&NBSP;&NBSP;
    10.   
    11. -(bool) shouldautorotate  
    12. {   
    13.     return yes;  
    14. }  



This allows for individual control of each view controller.


By the way, if all view controllers in the entire application do not support the spin screen, then simply:

    1. -(Nsuinteger) Application: (UIApplication *) application Supportedinterfaceorientationsforwindow: (UIWindow *) window
    2. {
    3. return uiinterfaceorientationmaskportrait;
    4. }



Next time, talk about IOS6 's memory control.

IOS6 control technique of rotary 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.