在uiwebview中播放youtube视频。如何处理“完成”按钮? [英] playing youtube video inside uiwebview. How to handle the "done" button?

查看:139
本文介绍了在uiwebview中播放youtube视频。如何处理“完成”按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个播放youtube视频的uiwebview。如何处理完成按钮操作?
现在,当我点击完成按钮时,它会更改回我的应用程序主菜单(不是应该关闭的菜单),它只是冻结。有人可以帮帮我吗?

I have a uiwebview that plays a youtube video. How can I handle the done button action? Right now, when I tap the done button it changes back to my app main menu (not the menu that was supposed to dismiss to) and it just freezes. Can anyone help me please?

Ps:uiwebview所在的菜单,以前是以模态方式呈现的。

Ps: the menu where the uiwebview is located, was previously presented modally.

推荐答案

YouTube插件播放器本身就是一个模态视图控制器。当按下完成按钮时,它返回到 presentsViewController 。它的 presentsViewController 不是你的模态视图控制器,而是调用 [presentModalViewController:animated:] 的viewController来呈现你的模态视图控制器。由于原始模态视图控制器仍处于活动状态,因此应用程序表现不佳。

The YouTube plug-in player is itself a modal view controller. It is returning to its presentingViewController when the done button is pressed. Its presentingViewController is not your modal view controller but is instead the viewController that called [presentModalViewController:animated:] to present your modal view controller. Since the original modal view controller is still active, the app behaves badly.

要解决此问题,

1)跟踪模态视图控制器是否已被呈现但未被解除。

1) Track whether the modal view controller has been presented but not dismissed.

2)在 viewDidAppear 方法中呈现视图控制器,如果模态视图控制器被呈现但未被解除,则解除并再次呈现它。

2) In the viewDidAppear method of the presenting view controller, if the modal view controller was presented and not dismissed, dismiss and present it again.

例如,在呈现模态Web视图控制器的控制器中:

For example, in controller that is presenting the modal web view controller:

 - (void) presentModalWebViewController:(BOOL) animated {
      // Create webViewController here.
      [self presentModalViewController:webViewController animated:animated];
      self.modalWebViewPresented = YES;
  }

  - (void) dismissModalWebViewController:(BOOL) animated {
      self.modalWebViewPresented = NO;
      [self dismissModalViewControllerAnimated:animated];
  }

  - (void) viewDidAppear:(BOOL)animated {
      [super viewDidAppear:animated];
      if (self.modalWebViewPresented) {
           // Note: iOS thinks the previous modal view controller is displayed.
           // It must be dismissed first before a new one can be displayed.  
           // No animation is needed as the YouTube plugin already provides some.
           [self dismissModalWebViewController:NO];
           [self presentModalWebViewController:NO];
      }
  }

这篇关于在uiwebview中播放youtube视频。如何处理“完成”按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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