目标是在iOS应用中同时允许平移和点按手势(以及其他手势)。然而,非常快速的平底锅有时被错误地解释为水龙头和平底锅。
UITapGestureRecognizer
的班级文档仅显示两个配置属性:numberOfTapsRequired
和numberOfTouchesRequired.
两者都不能帮助防止意外行为。
定义触摸在使抽头无效之前可以移动的最大距离将是理想的,即,如果用户移动他的手指> 10像素,不要将手势视为点击。
当前的方法似乎不利于光测试,是使用requireGestureRecognizerToFail
来对抗其他手势,这些手势不应该因为轻击手势而混淆。但是,一些用户建议实施自定义点击手势识别器。
requireGestureRecognizerToFail
是正确的方式,还是需要滚动自定义版本的UITapGestureRecognizer来消除不需要的行为?
private func setSceneViewGestureRecognizers() {
// Handle one-finger pans
let panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(sceneViewPannedOneFinger))
panRecognizer.minimumNumberOfTouches = 1
panRecognizer.maximumNumberOfTouches = 1
panRecognizer.delegate = self
sceneView.addGestureRecognizer(panRecognizer)
// Handle two-finger pans
let twoFingerPanRecognizer = UIPanGestureRecognizer(target: self, action: #selector(sceneViewPannedTwoFingers))
twoFingerPanRecognizer.minimumNumberOfTouches = 2
twoFingerPanRecognizer.maximumNumberOfTouches = 2
twoFingerPanRecognizer.delegate = self
sceneView.addGestureRecognizer(twoFingerPanRecognizer)
// Handle pinches
let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(sceneViewPinched))
pinchGesture.delegate = self
sceneView.addGestureRecognizer(pinchGesture)
// Handle taps
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(sceneViewTapped))
tapRecognizer.requireGestureRecognizerToFail(panRecognizer)
tapRecognizer.requireGestureRecognizerToFail(twoFingerPanRecognizer)
tapRecognizer.requireGestureRecognizerToFail(pinchGesture)
sceneView.addGestureRecognizer(tapRecognizer)
}