Domanda

How do I go about disabling auto rotation on every view controller of my application? I want each view/screen to only be viewed in portrait mode, I do not want my view controllers to transition to landscape mode if the phone is rotated. How can I go about doing this? I have seen too many confusing explanations/tutorials on the web. I have tried the following code on a particular view controller and it did not help, the view still rotated

- (NSInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (BOOL) shouldAutorotate {
    return YES;
}
È stato utile?

Soluzione

Just go to the summary of your application target and Check only the portrait mode.

enter image description here

Altri suggerimenti

go to Info.plist..find "Supported interface orientations" and keep only the option "Portrait (bottom home button)" and delete others options for landscape

in XCode, in the left hand nav bar, pick the File List. Then highlight your project name at the top. In the main editing view, you'll see a smaller left hand bar with two sections: PROJECTS and TARGETS. Highlight your application in the TARGETS section. You'll then see on the right of the editing view, across the top, 5 selections: SUmmary, Info, Build Settings, etc. Pick Summary. Scroll down just a bit and you'll see Supported Interface Orientations. Disable everything but the one you want.

That should do the trick.

PS. In your code example, the autorotate function should return NO if you don't want it to rotate.

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