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
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:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
In the parent controller disallow autorotate:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Create and assign a UINavigationControllerDelegate.
In the delegate, temporarily modify the UIView stack when the controller pops or pushes:
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
// Force portrait by changing the view stack to force autorotation!
if ([UIDevice currentDevice].orientation != UIInterfaceOrientationPortrait) {
if (![viewController isKindOfClass:[MovieWebViewController class]]) {
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *view = [window.subviews objectAtIndex:0];
[view removeFromSuperview];
[window insertSubview:view atIndex:0];
}
}
It's kind of a dirty hack, but it works.