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

查看:20
本文介绍了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.

例如,在我的应用程序中,我有一个 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天全站免登陆