iPad orientation change issue

心不动则不痛 提交于 2019-11-30 05:19:53

Apple states:

Case: All child view controllers in your UITabBarController or UINavigationController do not agree on a common orientation set.

Response: To make sure that all your child view controllers rotate correctly, you must implement shouldAutorotateToInterfaceOrientation for each view controller representing each tab or navigation level. Each must agree on the same orientation for that rotate to occur. That is, they all should return YES for the same orientation positions.

http://developer.apple.com/iphone/library/qa/qa2010/qa1688.html

You may be able to set device orientation within the navigation controller instead of within individual views. Then you could check which view is on the stack and rotate based on the result. In this way, the navigation controller handles all orientation as well.

Here is some code i'm using to prevent that error:

- (void)viewDidLoad {  
    if (self.interfaceOrientation == UIInterfaceOrientationPortrait) {
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(M_PI/2);
        self.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
    }
    [UIView commitAnimations];
}

and

- (void)viewDidLoad {
    if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(-(M_PI / 2));
        self.view.bounds = CGRectMake(0, 0, 320, 480);;
    }
    [UIView commitAnimations];
}

Based on what orientation the device is in, you will need to modify some of the code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!