UIWebView 模式 YouTube 播放器“完成”按钮动作

发布于 2024-11-06 12:13:12 字数 1515 浏览 1 评论 0原文

在我的 iPhone 应用程序中,我从主屏幕上呈现一个模态视图控制器,并使用 UIWebView 显示“内联”嵌入的 YouTube 视频:

UIWebView *youTubeWV = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 220)];
        [youTubeWV loadRequest:[NSURLRequest requestWithURL:sourceURL]];
        //NSString *youTubeVideoHTML = [NSString stringWithFormat:@"<embed id=\"yt\" src=\"http://www.youtube.com/watch?v=CadgUJRZfEE\" type=\"application/x-shockwave-flash\" width=\"320\" height=\"220\"></embed>"];
        NSString *youTubeVideoHTML =@"<html><head>"
        "<meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 220\"/></head>"
        "<body style=\"background:#FFFFF;margin-top:0px;margin-left:0px\">"
        "<div><object width=\"320\" height=\"220\">"
        "<param name=\"wmode\" value=\"transparent\"></param>"
        "<embed src=\"http://www.youtube.com/v/W-nzUoaI2Ss?f=user_favorites&app=youtube_gdata\""
        "type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"320\" height=\"220\"></embed>"
        "</object></div></body></html>";
        [youTubeWV loadHTMLString:youTubeVideoHTML baseURL:nil];
        [self.view addSubview:youTubeWV];

该视频在显示的模态视图“quicktime 播放器”中显示没有问题。但是,当我点击“完成”关闭第二个模式时,我会被踢回第一个屏幕,绕过第一个模式视图。在我的主屏幕上,现在所有按钮都不起作用。奇怪的!

更新:我从主屏幕中删除了模式转换,并将其改为“pushViewController”,现在一切正常。所以这是 YouTube 播放器同时关闭 2 个模态的问题。如何解决这个问题?

有什么想法吗?

In my iPhone app, I'm presenting a modal view controller from a home screen with a UIWebView that displays an "inline" embedded YouTube video using this:

UIWebView *youTubeWV = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 220)];
        [youTubeWV loadRequest:[NSURLRequest requestWithURL:sourceURL]];
        //NSString *youTubeVideoHTML = [NSString stringWithFormat:@"<embed id=\"yt\" src=\"http://www.youtube.com/watch?v=CadgUJRZfEE\" type=\"application/x-shockwave-flash\" width=\"320\" height=\"220\"></embed>"];
        NSString *youTubeVideoHTML =@"<html><head>"
        "<meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 220\"/></head>"
        "<body style=\"background:#FFFFF;margin-top:0px;margin-left:0px\">"
        "<div><object width=\"320\" height=\"220\">"
        "<param name=\"wmode\" value=\"transparent\"></param>"
        "<embed src=\"http://www.youtube.com/v/W-nzUoaI2Ss?f=user_favorites&app=youtube_gdata\""
        "type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"320\" height=\"220\"></embed>"
        "</object></div></body></html>";
        [youTubeWV loadHTMLString:youTubeVideoHTML baseURL:nil];
        [self.view addSubview:youTubeWV];

The video is displayed without problem in the modal view "quicktime player" that shows. However, when I tap "Done" to close the second modal, I get kicked back to the very first screen, bypassing my first modal view. And in my home screen, now all the buttons don't work. Strange!

UPDATE: I removed the modal transition from my home screen and made it a "pushViewController" instead, and now everything functions properly. So it's an issue of the YouTube player dismiss 2 modals at the same time. How can this be fixed?

Any ideas?

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

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

发布评论

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

评论(3

等待圉鍢 2024-11-13 12:13:12

我不确定,但似乎在按下“完成”按钮并且关闭播放器后,控件返回到根视图控制器,在您的情况下,这是您的第一个屏幕。

例如,在我的应用程序中,我有一个 UITabBarController 作为我的 rootViewController,在我的 AppDelegate 中,我有这样的东西:

self.window.rootViewController = self.myTabBarController;

这就是为什么我的 tabBarController (我的第一个屏幕)总是在按下“完成”按钮后出现的原因。

在呈现模态视图后,我解决了将模态视图设置为 rootViewController 的问题。

在呈现模态视图后尝试此操作:

MyAppDelegate *appDelegate = (MyAppDelegate *) [[UIApplication sharedApplication] delegate];
[self presentModalViewController: myModalViewController animated: YES];
[self.appDelegate.window setRootViewController: myModalViewController];

注意:在关闭模态视图后,您必须恢复根视图控制器

就我而言:

self.appDelegate.rootViewController = self.appDelegate.myTabBarController;

希望有帮助

I'm not sure but it seems that after the "done" button is pressed and the Player is closed the control returns to the root view controller, in your case that's your first screen.

For exaple in my application I have an UITabBarController as my rootViewController, in my AppDelegate I have something like this:

self.window.rootViewController = self.myTabBarController;

So that's the reason why my tabBarController (my first screen) always was presented after pressing the "done" button.

I solved this setting my Modal View as my rootViewController after presenting it.

Try this after presenting your modal view:

MyAppDelegate *appDelegate = (MyAppDelegate *) [[UIApplication sharedApplication] delegate];
[self presentModalViewController: myModalViewController animated: YES];
[self.appDelegate.window setRootViewController: myModalViewController];

NOTE: After dismissing the modal view you must restore the root view controller doing

In my case:

self.appDelegate.rootViewController = self.appDelegate.myTabBarController;

Hope it helps

聽兲甴掵 2024-11-13 12:13:12

不是一个确切的解决方案,但一种补丁可能会帮助您。

获取一个全局标志(可能位于 ApplicationDelegate 中),并在您点击 YouTube 页面上的 Done 按钮时将其设置为 true。在第一个控制器 viewWillAppear 中检查该标志是否为 TRUE,然后显示第二个控制器并再次将标志设置为 FALSE。

希望有帮助。

Not an exact solution but a kind of patch can may be help you out.

Take a global flag (may be in ApplicationDelegate) and set it to true when ever you tap on Done button on the youtube page. And in the very first controller viewWillAppear check if the flag is TRUE then present the second controller and turn the flag FALSE again.

Hope it helps.

逐鹿 2024-11-13 12:13:12

答案是:“在呈现它之后,我解决了将我的模态视图设置为我的 rootViewController 的问题。”是正确的做法。如果您从模态呈现的视图控制器调用 youtube,它将返回到呈现模态视图控制器的原始控制器。如果您随后尝试使用标志重新呈现正确的控制器,它会变得非常混乱,并且可能会出现计时问题。 Izaakcito 的方法工作正常。

The answer re: "I solved this setting my Modal View as my rootViewController after presenting it." is the correct approach. If you call youtube from a modally presented view controller it will return to the original controller which presented the modal one. If you then try to re-present the correct controller using flags it gets really messy and there can be timing issues. Izaakcito's method works properly.

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