Statement You are welcome to repost this article, but please respect the author's Labor achievements. repost this article and keep the statement in this box. Thank you. Article Source: http://blog.csdn.net/iukey |
Rotation is sometimes a good feature, but not all program interfaces want to rotate, because rotation will make the interface incompatible, unless you have developed a specific interface for various directions, so sometimes it is better to disable rotation, or a program interface is landscape. After exiting this landscape view, the interface becomes landscape, for example, when you watch a video or browse a webpage, you want to use a landscape screen, but you want to use a landscape screen for other work. OK. This is not a problem. We can use code to control the rotation function of each interface in our program.
In the View Controller you want to set, find the shouldautorotatetointerfaceorientation: method and rewrite its implementation code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);}
The system calls this method to query whether to control rotation in the specified direction. The system defines four directions, which correspond to four common grip modes:
typedef enum { UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight, UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft} UIInterfaceOrientation;
If you want to support rotation in any situation, you only need to return YES. If you only want to support partial rotation, no is returned for the supported Yes statements.
The Demo code: autooreintationdemo is attached.