UIWebView模态YouTube播放器“完成”按钮动作 [英] UIWebView modal YouTube player "Done" button action

查看:98
本文介绍了UIWebView模态YouTube播放器“完成”按钮动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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];

视频在模式视图quicktime player中显示没有问题。然而,当我点击完成关闭第二个模态时,我被踢回到第一个屏幕,绕过我的第一个模态视图。在我的主屏幕中,现在所有按钮都不起作用。奇怪!

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!

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

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?

任何想法?

推荐答案

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

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.

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

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;

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

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

我在演示后将我的模态视图解析为我的rootViewController。

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

Try this after presenting your modal view:

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

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

在我的情况下:

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

希望有所帮助

这篇关于UIWebView模态YouTube播放器“完成”按钮动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆