Launching app in landscape orientation causes rotation on launch
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 loa开发者_运维百科d 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.
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>
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...
精彩评论