我是UITextFIeld的子类。该文本字段包含在UITableViewCell中。我想抓住双击手势,但不是单击。双击启用编辑(没有问题),我希望单击传递到单元格以选择行。
我通过在UITextfield上放置一个视图(doubleTapView)并将手势识别器附加到该视图来实现此功能。当我想开始编辑时,我隐藏了这个视图,TextView正常工作。
func addDoubleTapView() {
doubleTapView = UIView(frame: bounds)
addSubview(doubleTapView!)
doubleTapRecognizer = UITapGestureRecognizer(target: self, action: #selector(doubleTap(_:)))
doubleTapRecognizer?.numberOfTapsRequired = 2
doubleTapRecognizer?.numberOfTouchesRequired = 1
doubleTapView?.addGestureRecognizer(doubleTapRecognizer!)
singleTapRecognizer = UITapGestureRecognizer(target: self, action: #selector(singleTap(_:)))
singleTapRecognizer?.requireGestureRecognizerToFail(doubleTapRecognizer!)
singleTapRecognizer?.numberOfTapsRequired = 1
singleTapRecognizer?.numberOfTouchesRequired = 1
singleTapRecognizer?.delegate = self
doubleTapView?.addGestureRecognizer(singleTapRecognizer!)
}
func doubleTap(sender: UITapGestureRecognizer) {
doubleTapView?.hidden = true
doubleTapView?.userInteractionEnabled = false
becomeFirstResponder()
}
我想忽略单击但不知道如何做到这一点。我不能用
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool
因为当触摸进来时我还不知道它是单击还是双击的开始。
如果有一种方法可以在响应者链上传递单击手势,我找不到它。
非常感谢任何帮助。
崖