In IOS 6 on iPad, initial rotation is always portrait, after that it always rotates correctly

谁说胖子不能爱 提交于 2019-12-05 22:11:21

After talking with Apple, they claim it is a bug in Xcode 4.5 on existing projects. Either you can create a new project and re-add everything (hard to do with a big project like ours). Or add you rotation logic something like this:

- (void)viewWillLayoutSubviews
{
    if ( ! afterFirstTime )
    {
        [self handleRotationFor:self.interfaceOrientation];
        afterFirstTime = YES;
    }
}

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [self handleRotationFor:toInterfaceOrientation];
}

on your root view controller. I got this answer right before their break Thanksgiving week so it might be a little sketchy, but this code does work.

If your application support portrait view, as MusiGenesis said; "iPad apps always start in portrait (even if the device is landscape) in iOS 5 as well."

But i found a solution to start in device orientation. You can set the initial rotation in the root ViewController, after viewDidLoad function as below.

The code seems to be pointless but it works.

No need to handle portrait rotation.

-(void)viewDidLoad {

[super viewDidLoad];
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) {
    [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationLandscapeLeft];

}
else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) {
    [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationLandscapeRight];

}

}

Regards.

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