2

I have implemented shouldAutorotateToInterfaceOrientation and everything works fine in terms or orientation changes in my app once it is running. However I don't like the behavior of my app when it is fist launched.

When I launch my app in portrait orientation, it opens as expected, however when I launch my app in landscape orientation, I see everything load in portrait orientation (including the status bar), then I see an animation of my screen rotating to landscape. That animation is fine, but I don't want it to be displayed at launch.

When I look at most other apps, they seem to detect the orientation as they launch and they do not show the rotation animation on launch (only if the device is rotated after launch time).

How can I make sure my app loads in the proper orientation so the user does not see the rotation animation on launch. I would prefer it if the user only saw the rotation animation if he/she rotates the device after launching.

Jackson
  • 3,555
  • 3
  • 34
  • 50

2 Answers2

5

Okay I think I figured it out. For anybody who created an app from an iPhone tempalte and then modified it for iPad, you need to add a line in your -info.plist file that says "Supported interface orientations" and enter all of the supported orientations as below. Then it seems to work as expected.

    <key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>
Jackson
  • 3,555
  • 3
  • 34
  • 50
  • Excellent. This fixed a problem I had. My app only supported landscape, but would launch upside down if the device wasn't in the orientation of the UIInterfaceOrientation setting. It would rotate quickly enough, but was annoying. (Also had to provide a proper launch image so it wouldn't start in portrait at times.) Thanks! (For others, this is documented here http://j.mp/fY56ml) – lilbyrdie Jan 28 '11 at 19:39
  • Glad I could help! feel free to vote up my answer or something so I can get points for answering my own question! :) – Jackson Feb 01 '11 at 05:41
0

I have done something like this in my Apps:

if ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeRight){
  [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
}else if ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeLeft){
  [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
}

Simply: detect Orientation at start and then set the StatusBarOrientation to that value. If you do this before you're loading your view (or at least, so earlier like possible within your App Structure), the statusbar should appear from beginning on the right side (so theres no rotation necessary). If you want to Support also portrait orientation, simply add 2 more else forks for them...

Constantin
  • 8,721
  • 13
  • 75
  • 126
  • I just tried this but I added two else ifs for UIInterfaceOrientationPortrait and UIInterfaceOrientationPortraitUpsideDown and it does not change anything. My app still launches, then the status bar changes, then the screen rotates to the correct orientation. :( I added it to didFinishLaunchingWithOptions in my app delegate. Is that where I should be adding it? – Jackson Dec 14 '10 at 14:35