iOS 11 AVPlayerViewController禁用捏合/拖动手势

时间:2017-09-28 08:20:54

标签: ios swift ios11 avplayerviewcontroller

我有一个AVPlayerViewController设置来播放视频,我在VC中查看自定义视图控制器中的视图。

但如果他们用户尝试,他们可以通过2指抓取来移动视频。如何禁用此功能?谢谢!

见下文:

Example of issue

2 个答案:

答案 0 :(得分:1)

在开始播放视频之前尝试这样的事情

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

答案 1 :(得分:1)

更安全的方法:

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

如果您不使用positions.reversed(),则在删除第一项并调整数组大小时,应用程序可能会崩溃。