Search code examples
ipaduiviewcontrollerorientationuisplitviewcontrollerlandscape

iPad Initial Orientation


I'm having a really hard time making my app to support all orientations correctly. The issue is with start up. I've done the following steps:

  1. Added :

    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    
  2. Made sure that all my view controllers always return YES in shouldAutorotateToInterfaceOrientation
  3. Added all the Default* images

When in landscape - the application starts showing the correct Default image, but then the actual app starts in portrait. The willRotate... and shouldAutorotate.. methods are not called.

I've even tried the swizzling method (from Wordpress):

+ (void)youWillAutorotateOrYouWillDieMrBond {
    NSLog(@"youWillAutorotateOrYouWillDieMrBond");
    Swizzle([NSClassFromString(@"UISplitViewController") class], @selector(shouldAutorotateToInterfaceOrientation:), @selector(MyShouldAutorotateToInterfaceOrientation:), NULL);
    Swizzle([NSClassFromString(@"UIViewController") class], @selector(shouldAutorotateToInterfaceOrientation:), @selector(MyShouldAutorotateToInterfaceOrientation:), NULL);
}

- (BOOL)MyShouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    NSLog(@"MyShouldAutorotateToInterfaceOrientation (%@)", self);
    return(YES);
}

Also with no luck. No matter what I do - if the device is in landscape, the app starts as portrait.

I've read the corresponding Apple docs - and they state that the applications always start in portrait but then rotate themselves if the VCs support the orientation. So seems I am doing everything as I should...

Really out of ideas here, would appreciate any insight.


Solution

  • Ok, thanks to everyone who helped, but it wasn't one of the proposed solutions: Seems I've stumbled on some iPAD bug.

    The solution was simple:

    The Master view didn't receive any events for some reason, and that was the problem. What I did was wrap that UIViewController inside a UINavigationController and set it as Master. Then the navigation controller DID receive the events and passed them on. Problem solved!