My root view controller's implementation of supportedInterfaceOrientations
almost always returns UIInterfaceOrientationMaskAll
, however there is one edge case where it returns UIInterfaceOrientationMaskLandscape
.
This is working, if the user rotates the device. However if the device is being held in portrait mode the supportedInterfaceOrientations
method does not ever get called, unless the user manually rotates the device.
How can I programatically tell the system that the return value of this method has changed?
According to the documentation, it seems like I should be able to call [UIViewController attemptRotationToDeviceOrientation]
however this does not have any effect (supportedInterfaceOrientations
is never called and the screen does not rotate).
I found various workarounds others have posted to try and solve this problem, but none of them work in my tests. I suspect they may have worked in iOS 5.0, but not iOS 6.0.
I am returning YES
in the root view controller's shouldAutorotate
method.
First of all, it might be useful if you used this if you want to present your UIViewController in Landscape mode.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}
Also, A lot depends on with which controller is your UIViewController embedded in.
Eg, If its inside UINavigationController, then you might need to subclass that UINavigationController to override orientation methods like this.
subclassed UINavigationController (the top viewcontroller of the hierarchy will take control of the orientation.) needs to be set it as self.window.rootViewController.
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
From iOS 6, it is given that UINavigationController won't ask its UIVIewControllers for orientation support. Hence we would need to subclass it.
Note :
The shouldAutorotate
and supportedInterfaceOrientations
method always get called for UINavigationController whenever Push operations are done.
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