4
votes

I have a strange problem in an iPhone app I'm developing. I want my app to support ONLY portrait mode, but for some reason I can't do it (device & simulator).

To support only portrait mode I did as follow:

  • In the TARGET summary section on Xcode, I chose only portrait.
  • All my ViewControllers implements shouldAutorotateToInterfaceOrientation

But as I said it won't work, and the strange result is that the app support ALL the orientations (portrait, upside down, landscape left, landscape right).
Any ideas?

this how I implement shouldAutorotateToInterfaceOrientation

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
     // Return YES for supported orientations
     NSLog(@"Checking orientation %d", interfaceOrientation);
     return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

I notice just now that when I rotate the phone I get this message:

"Two-stage rotation animation is deprecated. This application should use the smoother single-stage animation."

What does it means?

4
Try my answer. Maybe it will help.rohan-patel
Try adding NSLog(@"Checking orientation %d", interfaceOrientation); to your shouldAutorotateToInterfaceOrientation methods. Are any of them being called when you rotate the simulator or your device?Dondragmer
Thanks for your help, yes the log print "Checking orientation 1". But I noticed something else, please check my updated questionEyal
@Eyal: the additional console messages probably mean your code implements the old, and deprecated, didAnimateFirstHalfOfRotationToInterfaceOrientation:, and the similar willAnimateFirstHalfOfRotationToInterfaceOrientation:duration: and willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:. You can probably do without these methods.Dondragmer
@Eyal: interfaceOrientation of 1 is UIInterfaceOrientationPortrait, which is what you're expecting. If that really happens when you're rotating to landscape, this is weirder than ever: the device returns YES because it thinks it's rotating to portrait. Can you post a complete shouldAutorotateToInterfaceOrientation method?Dondragmer

4 Answers

4
votes

It is possible to have multiple ViewControllers on the screen. The UITabBarController is itself a UIViewController, and it only passes shouldAutorotateToInterfaceOrientation: requests to the viewControllers within if it chooses. The default implementation does this, but if you subclass it, the code XCode generates (as of iOS 5.1) does not.

9
votes

On the Target Summary choose portrait only.

5
votes

Go to info.plist file. Right Click open it as source code. And look for this line. For me in iPad its like this:

  <key>UISupportedInterfaceOrientations~ipad</key>

Delete all other orientation and keep the only one which you need..Like this :

    <array>

    <string> UIInterfaceOrientationPortrait </string>

</array>
2
votes

check your plist and make sure the key there is set correctly.