gpt4 book ai didi

ios - 显示控件时仅在 AVPlayerViewController 中显示 contentOverlayView

转载 作者:可可西里 更新时间:2023-11-01 06:05:24 34 4
gpt4 key购买 nike

我正在尝试使用 contentOverlayView 向 AVPlayerViewController 添加一个额外的按钮。问题是我只想在播放器控件显示时显示按钮。我觉得在这个阶段这是不可能的,但想确定一下。有人可以确认目前这是否可行吗?

最佳答案

假设您正在全屏运行 AVPlayerViewController,您可以将 UITapGestureRecognizer 添加到 Controller 的 View 中。但是需要一些 UIGestureRecognizerDelegate 方法。我将 subview 添加到 AVPlayerViewController 的 View 而不是 contentOverlayView。

let controller = AVPlayerViewController()
controller.player = self.player
let yourView = controller.view
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(VideoPlayer.onCustomTap(_:)))
tapGestureRecognizer.numberOfTapsRequired = 1;
tapGestureRecognizer.delegate = self
yourView.addGestureRecognizer(tapGestureRecognizer)

self.yourSubView = YourView()

controller.view.addSubview(yourSubView)
parentViewController.modalPresentationStyle = .FullScreen;
parentViewController.presentViewController(controller, animated: false, completion: nil)

将 UIGestureRecognizerDelegate 添加到您的类中,并检查任何触摸 View 的高度和宽度是否为屏幕高度和宽度。这个,虽然显然是 hacky 是我发现接近工作的唯一方法。播放器控件喜欢在播放 5 秒后消失并在结束时重新出现……这可能可以通过 AVPlayer 上的观察者来解决。我尝试走这条路,但像 ffwd 按钮这样的东西会让我放弃这个,转而使用自定义播放器。

extension VideoPlayer: UIGestureRecognizerDelegate {

func onCustomTap(sender: UITapGestureRecognizer) {

if yourSubView.alpha > 0{
UIView.animateWithDuration(0.5, animations: {
self.yourSubView.alpha = 0;
})

} else {
UIView.animateWithDuration(0.5, animations: {
self.yourSubView.alpha = 1;
})
}
}

public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {

if let _touchView = touch.view {

let screenRect:CGRect = UIScreen.mainScreen().bounds
let screenWidth :CGFloat = screenRect.size.width;
let screenHeight:CGFloat = screenRect.size.height;

if _touchView.bounds.height == screenHeight && _touchView.bounds.width == screenWidth{
return true
}

}
return false
}

public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
}

关于ios - 显示控件时仅在 AVPlayerViewController 中显示 contentOverlayView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31876702/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com