从 HTML5

发布于 2024-10-22 06:38:06 字数 885 浏览 2 评论 0原文

由于某些原因,我的应用程序仅支持纵向。
但是,在某些情况下,我需要显示来自 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 )

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

茶底世界 2024-10-29 06:38:06

我也做过类似的事情。您必须修改 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];
    }
}

这是一种肮脏的黑客行为,但它确实有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文