我有一个AVPlayerViewController
和自定义uicollectionviewcell
我怎么能禁用调用didSelectItemAtIndexPath
时触及AVPlayer从AVPLayerViewController?
单元格上有一堆其他元素,它们应该触发didSelectItemAtIndexPath
实际上在播放器控件上它是有效的,但是一旦它们淡出,在avplayer上的另一个触摸会触发didselect。
在同一个单元格中有一个uibutton,正确地取消触摸
一个hack的解决方案是覆盖你的单元格的hitTest
和取消选择时,球员视图点击:
class MyCell : UITableViewCell {
@IBOutlet private weak var videoContainer:UIView!
override func awakeFromNib() {
super.awakeFromNib()
// Settings up the video inside the cell :
let videoURL = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!
let player = AVPlayer(url: videoURL)
playerViewController = AVPlayerViewController()
playerViewController.player = player
player.play()
videoContainer.addSubview(playerViewController.view)
playerViewController.view.pinEdgesToSuperviewEdges()
}
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let convertedPoint = videoContainer.convert(point, from: self)
if let hitView = videoContainer.hitTest(convertedPoint, with: event) {
// The tap is somewhere inside the video view,
// disable user interaction on the cell and continue
self.isUserInteractionEnabled = false
return hitView
}
else {
// Tap is outside the video,
// use behavior that will trigger `didSelectItemAtIndexPath`
self.isUserInteractionEnabled = true
return super.hitTest(point, with: event)
}
}
}