IOS Autorotation and Autosizing

Source: Internet
Author: User

UIInterfaceOrientationPortrait: normal

UIInterfaceOrientationPortraitUpsideDown: Convert to 180 degrees

UIInterfaceOrientationLandscapeLeft: Turn left 90 degrees

UIInterfaceOrientationLandscapeRight: Right turn 90 degrees


1. After creating an AutoSize project, click AutoSizeViewController. m. You can see that the template provides a method named shouldAutorotateToInterfaceOrientation.

2. The system calls this method to check whether the View Controller is rotated in the specified direction.

-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) interfaceOrientation {

Return (interfaceOrientation = UIInterfaceOrientationPortrait );

}

 

3. The interfaceOrientation parameter will contain one of the following four values, and this method needs to return YES or NO to indicate whether the application window should be rotated to match the new direction. Since each View Controller subclass implements this method in different directions, an application may only support rotating some views, rather than rotating other views.

UIInterfaceOrientationPortrait,

UIInterfaceOrientationPortraitUpsideDown,

UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight

4. To enable automatic rotation, you only need to change the method to YES for any input value. For example

-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) interfaceOrientation {

Return YES;

}

5. If you only want to support some of the directions, you must check the value of interfaceOrientation, return YES For the value you want to support, and return NO for the value you don't want to support. For example, you need to support the backward and backward modes in two directions, but do not support the vertical mode from rotation to inversion. The Code is as follows:

-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) interfaceOrientation {

Return (interfaceOrientation = UIInterfaceOrientationPortrait |

InterfaceOrientation = UIInterfaceOrientationLandscapeLeft |

InterfaceOrientation = UIInterfaceOrientationLandscapeRight );

}

UIInterfaceOrientationPortrait: normal

UIInterfaceOrientationPortraitUpsideDown: Convert to 180 degrees

UIInterfaceOrientationLandscapeLeft: Turn left 90 degrees

UIInterfaceOrientationLandscapeRight: Right turn 90 degrees


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.