IPad launch orientation not detected

I have an iPad app that is working correctly except for an odd startup issue. I've read several questions and answers regarding orientation, but this still puzzles me.

The root view controller is a 3 tabbed UITabBarController. Two tabs have custom view controllers (one is based on UIViewController, the other is based on UITableViewController) and both suffer from this launch targeting issue. The third tab is the custom UITableViewController built into the UINavigationController.

OK, here's the problem. If I start the app in portrait orientation everything works fine. If I start it in landscape orientation the 3rd tab works fine. However, the first 2 tabs appear in portrait orientation, though:

  • The orientation of the status bar is correctly displayed as landscape (spread across the screen).
  • The tab bar display appears correctly as an album with centered tabs.
  • All views return YES for shouldAutorotateToInterfaceOrientation for all orientations.

If I call [self interfaceOrientation] or [[UIApplication sharedApplication] statusBarOrientation] in the WillAppear view controller, then the 3rd table view controller reports 3 (landscape), but the first two view managers report 1 (portrait) even though the status bar is clearly landscape!

If I rotate the iPad to portrait and switch back to landscape, then all 3 tabs rotate correctly (and the methods above return 3 as expected).

Also, if I click on any other tab and then go back to tab # 1 or # 2, they will now rotate correctly, even without rotating the iPad itself!

What am I missing?

+2


a source to share


6 answers


You must add the supportedDeviceOrientations to your "myApp.plist".

Click on this list, add the "Supported interface orientations" key and add the supported interface orientations. This solved the problem for me.



For more information follow this link and go to the Application Bundle section: http://developer.apple.com/iphone/library/documentation/General/Conceptual/iPadProgrammingGuide/CoreApplication/CoreApplication.html

+3


a source


I finally found my answer: I just forgot about it in my LoadController.



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return YES;
}

      

+1


a source


I found that device orientation starts at zero. And must return YES for Unknown. This will orient the device to the correct launch orientation.

Here is the code I used to read this post prior to legacy posts.

- (BOOL)shouldAutorotate{
    UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
    if (orientation == UIDeviceOrientationUnknown) return YES;
    BOOL result = [self shouldAutorotateToInterfaceOrientation:orientation];
    return result;
}

      

notice I am returning YES if orientation == UIDeviceOrientationUnknown. This fixed my upload problem.

+1


a source


just try this

- (BOOL)shouldAutorotateToInterfaceOrientation: UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown);<br>
}

      

0


a source


The solution is to add a key

UISupportedInterfaceOrientation

you Info.plist with an array of strings defining the supported orientations of the interface at startup, this

  • UIInterfaceOrientationPortrait

  • UIInterfaceOrientationPortraitUpsideDown

  • UIInterfaceOrientationLandscapeLeft

  • UIInterfaceOrientationLandscapeRight

However, there is a problem that can lead to confusion: . With at least SDK 3.2 and iPad Simulator from XCode 3.2.4 I found that (at least some) Info.plist settings appeared to be cached and / or not updated when the app was installed. That is, adding the key above and installing and running the application in the simulator had no effect. However, removing the app from the simulator fixed the issue where the newly installed app behaved as indicated.

0


a source


In the app delegate applicationDidFinishLaunchingWithOptions: after adding the view controller to the viewport, add the following:

[myViewController viewDidLoad];

      

This will call the shouldAutorotateToInterfaceOrientation: method if necessary.

0


a source







All Articles