iosswiftios11avplayerviewcontroller

iOS 11 AVPlayerViewController Disable Pinch / Drag Gesture


I have an AVPlayerViewController setup to play a video and them I am in-bedding the VC's view in a custom view controller.

But if they user tries they can move the video around by 2 finger grabbing. How do I disable this? Thanks!

See Below:

Example of issue


Solution

  • Try something like this before start playing video

    var positions = [Int]()
    for (idx, recognizer) in (playerVC.view.subviews[0].gestureRecognizers?.enumerated())! {
        if recognizer is UIPinchGestureRecognizer || recognizer is UIPanGestureRecognizer {
            positions.append(idx)
        }
    }
    for position in positions {
        playerVC.view.subviews[0].gestureRecognizers?.remove(at: position)
    }