Disable gesture recognizer in AVPlayerViewControll

2019-08-22 17:31发布

In AVPlayerViewController there is a feature for stopping the playback of a video and closing the AVPlayerViewController by swiping its view.

I want to disable this feature. I guess I need to disable a gesture recognizer!?

But I don’t know how to do this for the player.

1条回答
女痞
2楼-- · 2019-08-22 17:52

I recently stumbled upon a similar problem. You can access the gesture recognizers from the contentView of AVPlayerViewController.

If you wanted to keep only the tap gesture recognizer, you might want to use a function like this:

extension AVPlayerViewController {
    func disableGestureRecognition() {
        let contentView = view.value(forKey: "contentView") as? UIView
        contentView?.gestureRecognizers = contentView?.gestureRecognizers?.filter { $0 is UITapGestureRecognizer }
    }
}
查看更多
登录 后发表回答