Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an app launch in correct landscape orientation without rotating 180° at launch?

Tags:

ios

ios7

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:

enter image description hereenter image description here

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. enter image description here

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?

like image 966
iamjustaprogrammer Avatar asked Mar 29 '14 10:03

iamjustaprogrammer


People also ask

How do I force an app to landscape?

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

Can you change the orientation of an app?

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.

How do I force an app to landscape in IOS?

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.


1 Answers

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:

  • Delete the methods you posted from your AppDelegate, they won't get called.
  • Return all orientations in your controllers.
  • Then control your preferred orientations with your Info.plist (any iOS version).

Optional, if problems persist:

  • Try implementing application:supportedInterfaceOrientationsForWindow: in your AppDelegate (iOS 6+ only), which in general shouldn't be needed.
like image 126
Rivera Avatar answered Nov 03 '22 23:11

Rivera