我有一个UITableViewCell
和UIPickerView
。我想捕捉点击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/