问题
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