Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing landscape and autorotate in iOS 7

My app is supposed to be landscape only, and I had no problem with this when building for iOS 6 and earlier. Now with iOS 7, It won't rotate at all.

In my app settings, I have it set to landscape left/right only. In my view controller, i'm using the following:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}

I also used to use this, which is now deprecated:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
    return UIInterfaceOrientationIsLandscape(orientation);
}

The new one appears to be shouldAutorotate, but using this crashes my app. Any ideas on this would be appreciated, since my app is forced to portrait on my iPad and in the simulator. Thank you!

like image 822
ultra Avatar asked Sep 23 '13 12:09

ultra


People also ask

How do I put my iPhone 7 in landscape mode?

Swipe down from the top-right corner of your screen to open Control Center. Tap the Portrait Orientation Lock button to make sure that it's off. Turn your iPhone sideways.

How do I force an app to rotate 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'. As the names suggest, you can use these buttons as one-tap shortcuts to toggle the orientation of your device.


1 Answers

This solves my problem. I'm not sure why I had issues before, but I must have missed trying this exact combination (also, info.plist should have the supported orientations set).

(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

(BOOL)shouldAutorotate {
    return YES;
}

edit: I may have having issues with the simulator, and doing a reset/restart and clean might have contributed to the fix.

like image 154
ultra Avatar answered Oct 03 '22 07:10

ultra