【发布时间】:2016-04-13 22:43:24
【问题描述】:
根据文档,当 AVPictureInPictureController 关闭时,将调用 willStop 和 didStop 委托方法以及 restoreUserInterfaceForPictureInPictureStopWithCompletionHandler ,无论它是如何关闭的。如何判断控制器是否被“X”按钮或其他按钮关闭以返回常规播放?
【问题讨论】:
根据文档,当 AVPictureInPictureController 关闭时,将调用 willStop 和 didStop 委托方法以及 restoreUserInterfaceForPictureInPictureStopWithCompletionHandler ,无论它是如何关闭的。如何判断控制器是否被“X”按钮或其他按钮关闭以返回常规播放?
【问题讨论】:
X按钮和恢复按钮的区别是:
点击恢复画中画按钮会触发
"pictureInPictureController(_:restoreUserInterfaceForPictureInPictureStopWithCompl etionHandler:)"
"pictureInPictureControllerWillStopPictureInPicture"
"pictureInPictureControllerDidStopPictureInPicture"
点击关闭按钮时将跳过 restoreUserInterface 回调并直接进入
"pictureInPictureControllerWillStopPictureInPicture"
"pictureInPictureControllerDidStopPictureInPicture"
因此,您可以使用 Bool 标志检查 willStop/DidStop 是否调用了 restoreUserInterface。
AVPictureInPictureViewController 中还有一个 pictureInPictureSuspended 属性,但我尝试检查它的值并发现它在两种情况下总是返回 false,所以我必须使用上述技巧来检查用户是否点击了恢复或关闭按钮。
【讨论】: