【问题标题】:Simultaneous use of touch down and touch up gesture recognizers同时使用 touch down 和 touch up 手势识别器
【发布时间】:2013-08-05 18:22:35
【问题描述】:

我在UIView 上使用了两个手势识别器。一个是标准的UITapGestureRecognizer,另一个是我写的非常简单的touch down识别器:

@implementation TouchDownGestureRecognizer

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if (self.state == UIGestureRecognizerStatePossible) {
        self.state = UIGestureRecognizerStateRecognized;
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    self.state = UIGestureRecognizerStateFailed;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    self.state = UIGestureRecognizerStateFailed;
}

@end

只有当我为它们都分配一个包含此方法的委托时,它们才能一起工作:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

一切正常,但是当我在该视图上执行长按时,触摸识别器会触发而触摸识别器不会。对于短按,一切都很好,它们都会触发。

我在UIGestureRecognizerDelegate中实现了所有方法返回YES无济于事。如果我正在添加日志记录以查看与委托的交互以及在我自己的识别器内部,我可以看到对于短敲和长敲,调用顺序是相同的——除了对修饰识别器的调用。我做错了什么?

【问题讨论】:

    标签: iphone ios uikit uigesturerecognizer


    【解决方案1】:

    你为什么不直接从UILongPressGestureRecognizer检查touchUp?

    -(void)selectionDetected:(UILongPressGestureRecognizer*)longPress
    {
        if(longPress.state==1)
        {
           //long Press is being held down
        }
        else if(longPress.state==3)
        {
            //the touch has been picked up
        }
    }
    

    【讨论】:

    • 很好的建议,谢谢!该识别器需要将 minimumPressDuration 设置为 0,现在可以正常工作
    • 没问题很乐意提供帮助!
    猜你喜欢
    • 2012-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-23
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    相关资源
    最近更新 更多