Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In a shipping app that has worked correctly under iOS 5.X and supports all orientations, built against iOS 6 it always starts in portrait even when the ipad/simulator is in landscape).

I did add the new rotation methods

- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0);
- (NSUInteger)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);

but that makes no difference.

Note we do not use a navigation controller as the root view controller. Otherwise the app rotates correctly after the initial problem.

The root view controller handles all the decision making for rotations and is added to the main window as

    self.window.rootViewController = viewController;

I have all the rotations in the plist key set UISupportedInterfaceOrientations~ipad

Any ideas why the initial rotation is ignored?

Under 5.1 it calls shouldAutorotateToInterfaceOrientation and willRotateToInterfaceOrientation, etc. correctly but not under 6.0. If I build against 5.1 SDK then all is well.

like image 220
ahwulf Avatar asked Dec 01 '25 18:12

ahwulf


1 Answers

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.

like image 66
ahwulf Avatar answered Dec 05 '25 08:12

ahwulf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!