3

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.

Milan Nosáľ
  • 19,169
  • 4
  • 55
  • 90
Emily94
  • 75
  • 6

3 Answers3

3

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 }
    }
}
gtrochimiuk
  • 272
  • 2
  • 6
1

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)
    }
}
RoHaN
  • 372
  • 3
  • 14
0

Nothing worked for me, instead I used simply this one: (iOS 16)

controller.view.isUserInteractionEnabled = false
ugur
  • 824
  • 1
  • 7
  • 15