iOS >> Device Orientation >> Screen is Not Supporting Upside Down
Asked Answered
T

3

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?

Tjon answered 21/11, 2013 at 14:2 Comment(1)
V
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
Vespucci answered 21/11, 2013 at 14:49 Comment(5)
Yes, I guess this is needed only for Upside Down on iPhone, because that one is not supported by Navigation Controller by default.Vespucci
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?Tjon
@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.Vespucci
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).Bochum
You no longer need to subclass nav controller. You can set your VC as the delegate and implement - (UIInterfaceOrientationMask)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationControllerFreckle
A
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)

Anandrous answered 2/3, 2016 at 10:48 Comment(0)
P
0

Have you tested on real device?

anyway try this:

- (NSUInteger)supportedInterfaceOrientations {
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
Parsifal answered 21/11, 2013 at 14:14 Comment(2)
UIInterfaceOrientationMaskAll as posted will cover these as well.Lissotrichous
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...Tjon

© 2022 - 2024 — McMap. All rights reserved.