6

I have a screen that supports Device Orientation.

Everything is working fine except for the fact that when I rotate the device upside down (home button at top), the rotation doesn't work (it's stuck on the last landscape settings).

I know of several places needed be updated to support this:

  • In the VC itself, I added the methods:

enter image description here

  • In the Project Target, I updated as follow:

enter image description here

  • In the Storyboard VC Scene, I updated as follow:

enter image description here

What am I missing here?

1

3 Answers 3

11

You also have to allow rotating to all orientations in every parent view controller of the current main view controller. For example, if your view controller is in navigation controller, try subclassing it and override the same methods as in your example.

Edit: As @JordanC mentioned, since iOS 7 you can implement UINavigationControllerDelegate method to return custom supported orientations:

- (UIInterfaceOrientationMask)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController
5
  • 4
    Yes, I guess this is needed only for Upside Down on iPhone, because that one is not supported by Navigation Controller by default.
    – Tricertops
    Nov 21, 2013 at 14:57
  • BTW, So if I have several VCs on a navigation stack and I wish to have the first one NOT rotatable (while the ones that follow are) - It seems like once I've subclassed UINavigationController and set it to be rotatable, I cannot set its child VC to not accept rotation. Any thoughts?
    – Ohad Regev
    Nov 21, 2013 at 14:59
  • @OhadRegev I don’t think this is really possible. Try overriding supportedInterfaceOrientations of your navigation controller to return supported orientations of its topViewController. However, this would not prevent popping to the first view controller in illegal orientation. The only solution I see, is to disable „Back“ button when the previous VC doesn’t support current orientation.
    – Tricertops
    Nov 21, 2013 at 15:03
  • 1
    If a UITabBarController is present, note that you will have to subclass and override the - (UIInterfaceOrientationMask) supportedInterfaceOrientations {} method of that class as well (in addition to the UINavigationController).
    – eGanges
    Feb 23, 2016 at 21:27
  • You no longer need to subclass nav controller. You can set your VC as the delegate and implement - (UIInterfaceOrientationMask)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController
    – JordanC
    May 6, 2016 at 22:18
1

As @eGanges mentioned the key point could be to subclass your UITabBarController (and override supportedInterfaceOrientations) if that is your initial view controller, in that case this is the only controller you should subclass (and of course you should add all the supported interface orientations to your app Info.plist file UISupportedInterfaceOrientations key)

0

Have you tested on real device?

anyway try this:

- (NSUInteger)supportedInterfaceOrientations {
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
2
  • UIInterfaceOrientationMaskAll as posted will cover these as well.
    – rckoenes
    Nov 21, 2013 at 14:33
  • Well, I tested it on real device, and it has the same problem. Also, I've tried what you had suggested (using the | operator) and no good here as well...
    – Ohad Regev
    Nov 21, 2013 at 14:33

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.