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