I am facing a weird issue with a landscape-only app. It rotates just fine to landscape left or right, but when the app launches it rotates 180 degrees instead of just launching in the correct orientation.
I did everything I could find on StackOverflow and Google. The info plist contains:
Tested: iOS 7.1 completely ignores the initial launch orientation setting in the plist. I tried both left and right, and then deleted the key from info plist. No effect. App always launches in landscape with home button on the left, ignoring this setting.
When retrying, I delete the app and clean the build.
In App Delegate, I have this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
- (BOOL)shouldAutorotate {
return YES;
}
In the root view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
- (BOOL)shouldAutorotate {
return YES;
}
Some landscape apps like Tiny Wings launch in the correct orientation so I know something is wrong with my project. What is the secret sauce to get this working?
When on the main screen, under the orientation section, you will see a number of options like 'Auto-rotate OFF', 'Auto-rotate ON', 'Forced Portrait' and 'Forced Landscape'.
To change the orientation of individual apps, simply tap on them and select a new orientation mode from the list of available choices. The first three options define the new orientation for the app. They can be landscape, portrait or auto, which basically sets the orientation automatically.
On an iPhone with a Home button, swipe up from the bottom of the screen to access it. On an iPhone without a Home button, swipe down from the top-right corner of the screen instead. Here, tap on the rotation lock icon (which looks like a lock with a circular arrow) to turn it on or off.
First you don't need the three methods you have in your AppDelegate
as they are meant for controllers and won't get called anyway.
You could implement application:supportedInterfaceOrientationsForWindow:
(iOS 6+) although it says it's not needed with the correct keys in your Info.plist
:
Discussion
This method returns the total set of interface orientations supported by the app. When determining whether to rotate a particular view controller, the orientations returned by this method are intersected with the orientations supported by the root view controller or topmost presented view controller. The app and view controller must agree before the rotation is allowed.
If you do not implement this method, the app uses the values in the UIInterfaceOrientation key of the app’s Info.plist as the default interface orientations.
But if your problem is on iOS 6+ I would give it a try as it could be an Apple bug.
Also you could just return all orientations in your controller methods to keep it simple.
In sum:
AppDelegate
, they won't get called.Info.plist
(any iOS version).Optional, if problems persist:
application:supportedInterfaceOrientationsForWindow:
in your AppDelegate
(iOS 6+ only), which in general shouldn't be needed.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With