Domanda

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?

È stato utile?

Soluzione

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!).

Altri suggerimenti

The easiest way is to go to your project file and under the Deployment info part, check the orientation that you want to have for each device.

Edit: Here is the picture for your reference:

image

The easiest way to do this (no code required) is to go into your app's info.plist file, look for an entry called "Supported interface orientations" (Key = "UISupportedInterfaceOrientations"), click on it's disclosure triangle to display the list of supported orientations, and delete both landscape orientations.

That will prevent your entire app from switching to landscape.

If you want some view controllers to support different orientations then the supportedInterfaceOrientations method (new in iOS 6) is the way to go. The other poster's code using shouldAutorotateToInterfaceOrientation is for iOS 5.x and older.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top