Disable gesture recognizer in AVPlayerViewController

帅比萌擦擦* 提交于 2019-12-11 04:47:55

问题


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:


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 }
    }
}



回答2:


Removing gestures didn't worked for me. Adding a new UIPanGestureRecognizer without any action worked.

extension AVPlayerViewController {
    func disableGesture() {
        let panGesture = UIPanGestureRecognizer(target: self, action: nil)
        self.view.addGestureRecognizer(panGesture)
    }
}


来源:https://stackoverflow.com/questions/48538156/disable-gesture-recognizer-in-avplayerviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!