My app, for some reasons, only supports portrait orientation.
However, in some cases I need to display videos from a UIWebView (with video
tag) and it would be nice if the user can view it either in portrait or landscape.
The controller is configured like this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
Result: the video is played only in portrait mode (ok, quite expected).
I tried:
- setting this to support all orientations when the user starts a video
- when the video stops, back to "portrait only"
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
// autorotationEnabled is toggled when a video is played / stopped
return autorotationEnabled ? YES : UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
Result: landscape mode is available (great!) but if the user taps 'Done' while playing in landscape, the previous view will appear in landscape mode once the player is dismissed (not so great).
Does anybody have an idea on how to prevent the controller from being displayed in landscape mode when the player is dismissed?
(using the private method setInterfaceOrientation of UIDevice is not an option)
I've have done something very similar. You have to modify the UIView stack to force the app to call shouldAutorotateToInterfaceOrientation when you pop the controller.
In your WebViewController set to allow the autorotate:
In the parent controller disallow autorotate:
Create and assign a UINavigationControllerDelegate.
In the delegate, temporarily modify the UIView stack when the controller pops or pushes:
It's kind of a dirty hack, but it works.