我在视图上点按两次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)
当我双击子视图时,会触发这两个操作。我怎样才能让单击手势"取消"双击手势?
答案 0 :(得分:1)
使用requireGestureRecognizerToFail
在识别器之间创建关系。例如:
gr2.requireGestureRecognizerToFail(gr)
更新:正如评论中提到的@ tumber033,在他的示例中gr2
和gr
应该互换,以便应该有
parentGR.requireGestureRecognizerToFail(childGR)