简体   繁体   English

在父视图上双击手势,在子视图上单击手势

[英]Double tap gesture on parent view and single tap gesture on child view

I have a double tap UITapGestureRecognizer on a view and a single tap UITapGestureRecognizer on it's child view. 我在视图上有一个双击的UITapGestureRecognizer ,在它的子视图上有一个单击的UITapGestureRecognizer

    let parentGR = UITapGestureRecognizer(target: self, action: "doubleTappedParent")
    parentGR.numberOfTapsRequired = 2
    parentView.addGestureRecognizer(parentGR)

    let childGR = UITapGestureRecognizer(target: self, action: "singleTappedChild")
    childGR.numberOfTapsRequired = 1
    childView.addGestureRecognizer(childGR)

When I double tap the child view, both actions are triggered. 当我双击子视图时,两个动作都被触发。 How can I have it such that the single tap gesture "cancels" the double tap gesture? 我如何才能使单击手势“取消”双击手势?

Create a relationship between recognizers using requireGestureRecognizerToFail . 使用requireGestureRecognizerToFail在识别器之间创建关系。 For instance: 例如:

gr2.requireGestureRecognizerToFail(gr)

Update: as @tumber033 mentioned in the comment, in his example gr2 and gr should be swapped, so that there should be 更新:正如评论中提到的@ tumber033,在他的示例中gr2gr应该交换,这样就应该有

parentGR.requireGestureRecognizerToFail(childGR)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM