Rotating Screen Control Technique of ios6

Source: Internet
Author: User

Rotating Screen Control Technique of ios6

In ios5.1 and earlier versions, we usually useShouldautorotatetointerfaceorientation:To independently control the orientation of a uiviewcontroller, such:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{    return (interfaceOrientation == UIInterfaceOrientationPortrait);}

However, in ios6, this method is discarded and invalid.

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 .)

After practice, you will find thatSupportedinterfaceorientationsThe screen cannot be locked.

-(NSUInteger)supportedInterfaceOrientations{    return UIInterfaceOrientationMaskPortrait;}

After multiple experiments, we can summarize the following methods to control the orientation of screen rotation:

SubclassUinavigationcontroller, add Method

- (BOOL)shouldAutorotate{    return self.topViewController.shouldAutorotate;}- (NSUInteger)supportedInterfaceOrientations{    return self.topViewController.supportedInterfaceOrientations;}

And set it as the program entry, or as self. Window. rootviewcontroller

Then add your own view controller. If you want to disable the rotating screen of a View Controller: (all versions are supported)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{    return (interfaceOrientation == UIInterfaceOrientationPortrait);}-(BOOL)shouldAutorotate{    return NO;}-(NSUInteger)supportedInterfaceOrientations{    return UIInterfaceOrientationMaskPortrait;}

If you want to enable full-direction screen rotation of a view controller, you can:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);}-(NSUInteger)supportedInterfaceOrientations{    return UIInterfaceOrientationMaskAllButUpsideDown;}-(BOOL)shouldAutorotate{    return YES;}

Thus, the independent control of each View Controller is implemented.

By the way, if all view controllers of the application do not support screen rotation, simply:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{     return UIInterfaceOrientationMaskPortrait;}

Let's talk about ios6 memory control next time.

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.