简体   繁体   中英

iOS application starts in LandscapeRight when device in LandscapeLeft

I have an iOS app for an iPhone that displays information on the screen. The Deployment Info indicates that LandscapeLeft and LandscapeRight are supported.
When I start my app with the device in LandscapeRight, then everything is fine and turning my device to LandscapeLeft reverts my whole image by 180 degrees and the displayed information are still ok.
Now if I start the application with my device turning in LandscapeLeft, the the application will anyway start in Landscape Right and I have to do a full physical turn of my device to have the right orientation detected.
Basically if I add the code at the beginning of my ViewController viewDidLoad:

if ([UIApplication sharedApplication].statusBarOrientation == UIDeviceOrientationLandscapeLeft)
{
    NSLog(@"LandscapeLeft");
}
else  if ([UIApplication sharedApplication].statusBarOrientation == UIDeviceOrientationLandscapeRight)
{
    NSLog(@"LandscapeRight");
}

always displays LandscapeRight.

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration

is not called if my device orientation does not change physically. Any suggestion how I can detect the real orientation ? Thanks.

=== EDIT ===
I just found out something interesting. If I keep the Launchscreen in the .plist file (I removed it) and related default Launchscreen.xib, then it works fine. How can I properly have ;y desired behaviour without launch screen ?

you have to check you .plist file setting...

In your application's "Info.plist" file, add the UISupportedInterfaceOrientations key with the UIInterfaceOrientationLandscapeLeft and UIInterfaceOrientationLandscapeRight values

<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>

For more information refer documentation link https://developer.apple.com/library/ios/technotes/tn2244/_index.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM