iOS 11 AVPlayerViewController Disable Pinch / Drag Gesture

眉间皱痕 提交于 2021-01-08 02:30:34

问题


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:


回答1:


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



回答2:


More safe way of doing it:

    let recognizers: [UIGestureRecognizer] = view.subviews.first?.gestureRecognizers ?? []
    for (idx, recognizer) in recognizers.enumerated() {
        if recognizer is UIPinchGestureRecognizer || recognizer is UIPanGestureRecognizer {
            positions.append(idx)
        }
    }
    for position in positions.reversed() {
        view.subviews.first?.gestureRecognizers?.remove(at: position)
    }

if you don't use positions.reversed() app may crash when removes the first item and the array gets resized.



来源:https://stackoverflow.com/questions/46464286/ios-11-avplayerviewcontroller-disable-pinch-drag-gesture

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