4

我嵌入了一个 iframe 视频,我想检测用户何时退出(点击“完成”)移动 Safari 上的全屏功能,该功能在您点击“播放”时发生。我尝试了下面的代码:

HTML

<iframe id="video-iframe" src="//player.vimeo.com/video/105953491?title=0&amp;byline=0&amp;portrait=0&amp;api=1" width="100%" height="100%" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

JavaScript

document.getElementById("video-iframe").addEventListener("webkitendfullscreen", function(){
  alert("Hello World!");
});

演示:http: //jsfiddle.net/p3bLohfk/

但它不起作用(iOS 8.0.2)。有任何想法吗?

4

1 回答 1

-1

在 iOS 8 上,当系统视频播放器从 iOS 上接管时UIWebView,应用程序的主窗口是隐藏的。监听视图控制器上的UIWindowDidBecomeHiddenNotificationUIWindowDidBecomeVisibleNotification通知,以检测用户何时进入和退出全屏播放器:

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(videoDidExitFullScreen:)
                                                 name:UIWindowDidBecomeVisibleNotification
                                               object:self.view.window];

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(videoDidEnterFullScreen:)
                                                 name:UIWindowDidBecomeHiddenNotification
                                               object:self.view.window];
于 2016-02-11T04:02:07.240 回答