1

How can i make my app to be always in portrait mode only. If i rotate iPhone it should not display app in landscape mode.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortrait);

return YES;
}

After this coding when i rotate iPhone app is displayed in landscape mode. How can i make app to be in portrait mode all the time.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
user1120133
  • 3,244
  • 3
  • 48
  • 90
  • 3
    dupe of http://stackoverflow.com/questions/10032490/how-to-support-only-portrait-mode-on-an-iphone-app – rishi May 04 '12 at 18:52
  • 1
    Good answer below, and for future reference, "!=" means not equal to, so the code you posted tells your app to return any orientation except portrait. – Mick MacCallum May 12 '12 at 11:11

3 Answers3

9

Remove the method — you don't need it. An iPhone app always starts in portrait mode unless you force it to start in landscape mode. If this method is absent, it will stay in portrait mode, as it effectively means "My view won't respond to interface orientation changes."

Incidentally, this method actually starts out commented out in Xcode's view controller templates, which is the same as it not being there at all.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
5

In xcode click left top on your project name and then right below of "TARGETS" you can set "Supported Device Orientations".

iWizard
  • 6,816
  • 19
  • 67
  • 103
0

Seems for iOS 6 you need to override this method,

-(BOOL)shouldAutorotate {
    return NO;
}
karim
  • 15,408
  • 7
  • 58
  • 96