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.