iOS:在快速平移手势期间错误识别的轻击手势。使用requireGestureRecognizerToFail或创建自定义点击手势识别器?

时间:2016-08-25 01:11:39

标签: ios swift uigesturerecognizer uipangesturerecognizer uitapgesturerecognizer

目标是在iOS应用中同时允许平移和点按手势(以及其他手势)。然而,非常快速的平底锅有时被错误地解释为水龙头和平底锅。

UITapGestureRecognizer的班级文档仅显示两个配置属性:numberOfTapsRequirednumberOfTouchesRequired.两者都不能帮助防止意外行为。

定义触摸在使抽头无效之前可以移动的最大距离将是理想的,即,如果用户移动他的手指> 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)
}

0 个答案:

没有答案