UITapGestureRecognizer

UITapGestureRecognizer

我有一个UITableViewCellUIPickerView。我想捕捉点击1个元素的事件(所以不是pickerView(_:didSelectRow:inComponent:)的作用)

这是我的课:

class PickerTableViewCell: UITableViewCell {

    @IBOutlet var pickerView:UIPickerView!

    private var gestureRecognizer:UITapGestureRecognizer!

    override func awakeFromNib() {
        gestureRecognizer = UITapGestureRecognizer(target: self, action: "didTap:")
        gestureRecognizer.cancelsTouchesInView = false
        pickerView.addGestureRecognizer(gestureRecognizer)
    }

    func didTap(gestureRecognizer:UITapGestureRecognizer) {
        print("tap")
    }

    override func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return true
    }
}


正如其他响应中所建议的那样,我覆盖了UIGestureRecognizerDelegate的方法shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer以返回true,但这无济于事。

最佳答案

我需要添加UITapGestureRecognizer的设置委托。

gestureRecognizer.delegate = self


因为我已经覆盖了shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer,所以做了这份工作!

关于ios - UIPickerView的UITapGestureRecognizer不会触发,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33733205/

10-12 07:14