[IOS] iOS 6 Rotation

Source: Internet
Author: User

The rotation of iOS 6 has changed a lot. Let's take a look at the official description.

Http://www.bgr.com/2012/08/06/ios-6-beta-4-change-log-now-available/

Knowledge point:

* The shouldautorotatetointerfaceorientation method of uiviewcontroller is deprecated. In ios6, supportedinterfaceorientations and shouldautorotate are used to replace shouldautorotatetointerfaceorientation. Note: To be backward compatible with IOS 4 and 5, you still need to keep shouldautorotatetointerfaceorientation in your app.

For IOS 4 and 5, if shouldautorotatetointerfaceorientation is not rewritten, for iPhone, by default only supports portrait and cannot be rotated.

For iOS 6, if shouldautorotate and supportedinterfaceorientations are not rewritten, by default, the iPhone is "rotated, supports non-upside down directions", and the iPad is "selectable, supports all directions"

Example 1: for iOS 4 and 5, iPhone device, if you want to "rotate, support non-upside down direction", you can

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {return (interfaceOrientation != UIDeviceOrientationPortraitUpsideDown);}

Example 2: for iOS 6, iPhone device, to "cannot rotate, only support portait", you can

- (BOOL)shouldAutorotate{    return NO;}

Example 3: for iOS 6, iPad device. To "rotate, only landscape" is supported, you can

-(NSUInteger)supportedInterfaceOrientations{    return UIInterfaceOrientationMaskLandscape;}- (BOOL)shouldAutorotate{    return YES;}

* In IOS 4 and 5, the orientation settings of the corresponding view are determined by the specific view controller. In iOS 6, the top-most Controller determines the orientation settings of the view.

For example, the rootviewcontroller of your app is navigation controller "nav", and the stack in "nav" is: main view-> sub View> sub view, in the main view, a button will present modal view "Modal View ".

For IOS 4 and 5, in the iPad, if you want the preceding view to only support horizontal screen orientation, you need to go to the main view, sub view, sub view, add both in Model View

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight);}

For ios6, the top-most controller is used to set orientation. Therefore, adding the following code to main view, sub view, and sub view has no effect, instead, add the following code to the nav controller. Modal view is not in NAV container, so you also need to add the following code in modal view.

-(NSUInteger)supportedInterfaceOrientations{    return UIInterfaceOrientationMaskLandscape;}- (BOOL)shouldAutorotate{    return YES;}

Note:

* You need to customize a uinavigationcontroller subclass for "nav controller" to add the above Code.

* Similar to navigation controller, the orientation settings of each view in tab controller should be placed in tab controller.

The top-most controller of for ios6 decides the orientation settings, resulting in the following problem: Views in the top-most controller cannot have different orientation settings. For example, for iPhone, in NAV controller, you have main view, sub view and sub view. The first two views can only be vertical, while sub view is used to play video, it can be vertical or horizontal. In IOS 4 and 5, you can set only vertical positions in shouldautorotatetointerfaceorientation of main view and sub view.
Set shouldautorotatetointerfaceorientation in sub view to vertical. This effect cannot be achieved in iOS 6, because the orientation settings of main view, sub view and sub view are invalid and can only be set in NAV controller. You may want to use the following code to control which view is vertical and which view is horizontal in the nav controller.

-(NSUInteger)supportedInterfaceOrientations{    if([[self topViewController] isKindOfClass:[SubSubView class]])        return UIInterfaceOrientationMaskAllButUpsideDown;    else        return UIInterfaceOrientationMaskPortrait;}

Yes, this will make it impossible to strike a horizontal chart in the main view and sub view, while the sub view can be both horizontal and vertical. However, the problem arises. If the sub view is horizontal and then back to sub view, the sub view is horizontal!

Currently, we can only remove the sub view from the nav controller and display it in modal view mode. In this way, you can set horizontal and vertical in the modal view, and set only vertical in the nav controller.

* If the orientation settings of all views of your app are unified, you can simply set them in plist file without adding the above Code. If you add the above code, it will overwrite the orientation settings in plist.

* In iOS 6, when View Controller present, willrotatetointerfaceorientation: Duration:, willanimaterotationtointerfaceorientation: Duration:, and didrotatefrominterfaceorientation: methods will be called only when rotate occurs.

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.