自动旋转从UIWebView中的HTML5

|| 由于某些原因,我的应用仅支持纵向。 但是,在某些情况下,我需要显示来自UIWebView的视频(带有
video
标签),如果用户可以纵向或横向查看视频,那就太好了。 控制器的配置如下:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
结果:视频仅在纵向模式下播放(好的,完全可以预期)。 我试过了: -设置此选项以在用户开始播放视频时支持所有方向 -视频停止播放后,返回“仅限人像”
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    // autorotationEnabled is toggled when a video is played / stopped
    return autorotationEnabled ? YES : UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
结果:可以使用横向模式(很好!),但是如果用户在横向播放过程中轻按“完成”,则一旦退出播放器,前一个视图将以横向模式显示(不是很好)。 是否有人对关闭播放器时如何防止控制器在横向模式下显示? (不可使用UIDevice的私有方法setInterfaceOrientation)     
已邀请:
我做过非常类似的事情。您必须修改UIView堆栈,以在弹出控制器时强制应用程序调用shouldAutorotateToInterfaceOrientation。 在您的WebViewController中设置为允许自动旋转:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
在父控制器中禁止自动旋转:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
创建并分配一个UINavigationControllerDelegate。 在委托中,当控制器弹出或推动时临时修改UIView堆栈:
- (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];
    }
}
这有点肮脏,但是可以。     

要回复问题请先登录注册