IPhone automatic rotation control code-iOS development

Source: Internet
Author: User
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.

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.