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:
What am I missing here?
The device, application and view controller all need to agree for the orientation to work. By default, a view controller doesn’t allow upside down on an iPhone regardless of what you specify for the application. To fix this, we can override this property in the view controller and return .all.
To rotate upside down on older iPhones add upside down as a supported orientation in Info.plist or using the App delegate and override the supported interface orientations in the root view controller (you probably shouldn’t do this). But the plans were on display…
By default, a view controller doesn’t allow upside down on an iPhone regardless of what you specify for the application. To fix this, we can override this property in the view controller and return .all.
The device, application, and view controller settings must all agree for an orientation to work. To rotate upside down on older iPhones add upside down as a supported orientation in Info.plist or using the App delegate and override the supported interface orientations in the root view controller (you probably shouldn’t do this).
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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With