Autorotating video played from HTML5 <video> in UIWebView

喜欢而已 提交于 2019-11-30 14:51:48
Steven Veltema

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!