Disable landscape orientation for iOS 7 application?

Cescy picture Cescy · Jan 22, 2014 · Viewed 14.2k times · Source

First time developer and have just setup the certificates to be able to run my application on an iOS device.

My application does not view nicely in landscape mode even with Autolayout setup. How can I disable the user from being able to view the app in landscape when they turn the device? i.e. its always portrait regardless of the orientation of the device? thanks

EDIT: Does Apple also advise against doing this during submission?

Answer

Nathaniel picture Nathaniel · Jan 22, 2014

As Siavash said, the General Tab in your Target is the best place to limit the orientations for the entire device. Device orientations

If you wanted to set all orientations possible but limit it for certain View Controllers, you could do something like this:

- (BOOL) shouldAutorotate
{
    return NO;
}

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    if (condition)
    {
        return UIInterfaceOrientationPortrait;
    }else{
        return UIInterfaceOrientationLandscapeLeft;
    }
}

To answer your second question, Apple does not critique an app based on its possible orientations. It's more up to you to decide which orientation(s) is/are best suited for your app. For iPhone Apps, users prefer Portrait usually for example (unless it's a game!).