双击手势在父母视图和单击子手势上儿童视图

时间:2016-02-25 09:05:53

标签: ios swift

我在视图上点按两次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)

当我双击子视图时,会触发这两个操作。我怎样才能让单击手势"取消"双击手势?

1 个答案:

答案 0 :(得分:1)

使用requireGestureRecognizerToFail在识别器之间创建关系。例如:

gr2.requireGestureRecognizerToFail(gr)

更新:正如评论中提到的@ tumber033,在他的示例中gr2gr应该互换,以便应该有

parentGR.requireGestureRecognizerToFail(childGR)