2

I have an iPad app that works correctly except for an odd issue during launch. I've read several questions & answers regarding orientation, but this still has me stumped.

The root view controller is a UITabBarController with 3 tabs. Two of the tabs are have custom view controllers (one based off of UIViewController, the other off of UITableViewController) and both suffer from this launch orientation problem. The third tab is a custom UITableViewController that's embedded in a UINavigationController.

OK, here's the problem. If I start the app in Portrait orientation, everything works great. If I start it in Landscape orientation, the 3rd tab works perfectly. However, the first 2 tabs come up in Portrait orientation, even though:

  1. The status bar orientation correctly shows as landscape (spread across the screen).
  2. The Tab Bar view correctly shows as landscape with the tabs centered.
  3. All views return YES for shouldAutorotateToInterfaceOrientation for all orientations.

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

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

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

What am I missing?

Madhup Singh Yadav
  • 8,110
  • 7
  • 51
  • 84
Gorm
  • 2,714
  • 1
  • 18
  • 12
  • Maybe I should rewrite the question. In a nutshell what happens is that the views are rotated, but they are not resized. So in landscape mode, they show up as landscape, but the right side of the screen is white and there is some of the view hidden on the bottom. This only happens when my views are embedded directly in the Tab controller. If my views are inside a Navigation controller inside the Tab controller, then they are resized correctly. They are getting the "willRotateTo..." and "didRotateFrom..." messages correctly. They rotate, they just don't resize. – Gorm Apr 29 '10 at 15:04

6 Answers6

3

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

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

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

Pascal Klein
  • 23,665
  • 24
  • 82
  • 119
  • 2
    Thanks, but I already have "Supported interface orientations (iPad)" with 4 values and "Supported interface orientations" with 1 value in my plist (the iPhone version can only be used vertically, but the iPad version works in any orientation). I don't see any reference to supportedDeviceOrientations, so I assume that was a typo? – Gorm Jul 30 '10 at 15:00
1

I have found that the device orientation starts out with nothing. And should return YES for Unknown. This will allow it to orient the device with the correct launch orientation.

Here is the code I used to propigate this message up to the legacy messages.

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

notice I return YES if orientation == UIDeviceOrientationUnknown. This corrected my loading problem.

The Lazy Coder
  • 11,560
  • 4
  • 51
  • 69
1

I finally found my answer: I just forgot this in my LoadingController.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return YES;
}
William Remacle
  • 1,480
  • 2
  • 16
  • 24
0

just try this

- (BOOL)shouldAutorotateToInterfaceOrientation: UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown);<br>
}
Kev
  • 118,037
  • 53
  • 300
  • 385
user440485
  • 787
  • 2
  • 11
  • 20
0

The solution is to add a key

UISupportedInterfaceOrientation

to you Info.plist with an array of strings specifying the suppored interface orientations at launch time, these are

  • UIInterfaceOrientationPortrait
  • UIInterfaceOrientationPortraitUpsideDown
  • UIInterfaceOrientationLandscapeLeft
  • UIInterfaceOrientationLandscapeRight

However, there is the follwing issue which may lead to confusion: At least with 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 are not updated when installing the app. That is, adding the key above and installing and launching the app in the simulator had no effect. However, deleting the app from the simulator fixed the problem an the newly installed app behaved as specified.

Christian Fries
  • 16,175
  • 10
  • 56
  • 67
0

In your app delegate's applicationDidFinishLaunchingWithOptions: method, after you add your view controller's view to the window, add the following:

[myViewController viewDidLoad];

If necessary, this will trigger a call to the shouldAutorotateToInterfaceOrientation: method.

William Jockusch
  • 26,513
  • 49
  • 182
  • 323