For how to set the horizontal and vertical screen of iOS, reprinted in ios

Source: Internet
Author: User

For iOS horizontal and vertical screen setting (reprinted), ios reprinted

The horizontal screen and vertical screen of the iPhone are developed in two ways for the iOS system version: one is the use mode before iOS 6, and the other is the new mode of iOS6. The difference between the two is quite large.

1: shouldAutorotateToInterfaceOrientation is usually used before iOS6 to separately control the direction of a UIViewController. Which viewController needs to support rotation? You only need to override the shouldAutorotateToInterfaceOrientation method. In the following example, after setting, only horizontal screen conversion is supported when the screen is rotated:-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) interfaceOrientation {return UIInterfaceOrientationIsLandscape (interfaceOrientation );} after iOS6, use the following two methods to control automatic rotation:-(BOOL) shouldAutorotate {NSLog (@ "to prevent me from rotating? "); Return YES;}-(NSUInteger) supportedInterfaceOrientations {NSLog (@" "); return UIInterfaceOrientationMaskAllButUpsideDown;} after automatic rotation is triggered, the system automatically calls the other two methods:-(void) willRotateToInterfaceOrientation :( UIInterfaceOrientation) toInterfaceOrientation duration :( NSTimeInterval) duration {[super duration: toInterfaceOrientation duration: duration]; NSLog (@ "is it about to rotate? ");}-(Void) rotate :( UIInterfaceOrientation) fromInterfaceOrientation {[super didRotateFromInterfaceOrientation: fromInterfaceOrientation]; NSLog (@" if you want me to rotate, I have already completed the rotation! ");} 2: display the landscape screen or landscape screen immediately when the program is started for the first time. If it is before iOS6, the following device support direction can be modified in the application. If it is iOS6, it will be used as a hard condition, that is, if it is set later, the code in the application can no longer use this direction. 3. The legendary private API implements the option of switching the ViewController to force a horizontal screen. if ([[UIDevice currentDevice] respondsToSelector: @ selector (setOrientation :)]) {[[UIDevice currentDevice] performSelector: @ selector (setOrientation :) withObject :( id) UIInterfaceOrientationLandscapeRight];} 4: When xib is used for interface design, the xib display mode is changed.

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.