开发者

iPad launch orientation not detected

I have an iPad app that works correctly exc开发者_如何转开发ept 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?


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


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

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


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 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.


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.


just try this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜