I have a UIViewController that is presented modally (fullscreen), and I would like to disable autorotation in this view. I do not want to limit it to a landscape or a portrait, I just want him to stay in any orientation that he originally represented.
In iOS 6, it was enough to simply override the method:
- (BOOL)shouldAutorotate { return NO; }
And he did exactly what I wanted. However, this does not seem to affect iOS 7. The method is called, but the return value is apparently ignored by the OS - it automatically rotates no matter what.
The documentation does not mention changes to this method. How can I achieve the desired effect on iOS 7?
Edit: The view controller is displayed (did not click!) On the UINavigationViewController :
[self.navigationController presentViewController:vc animated:YES completion:nil];
Decision:
Oddly enough, but this decision was not published in numerous existing issues on this topic. On iOS 7, it seems that the response of the UINavigationController gives shouldAutorotate - this is what the OS is acting on. We need to subclass UINavigationController to change its behavior.
When working with a normal navigation stack, it is really quite simple to use [self.topViewController shouldAutorotate] , but when there is a modal view, it is in self.presentedViewController , not self.topViewController . So the complete solution looks like this:
- (BOOL)shouldAutorotate { UIViewController *vc; if (self.presentedViewController) vc = self.presentedViewController; else vc = [self topViewController]; return [vc shouldAutorotate]; }
ios objective-c cocoa-touch uiviewcontroller
Saltynuts
source share