我有一个UIView(蓝色),我想检测它的手势识别器。我想在这个视图上捕捉平移和点按手势,但是当用户点击此视图时,我希望"交付"此触摸/点按父视图(绿色)。
我的蓝色UIView:
class SwipeView: UIView, UIGestureRecognizerDelegate {
var tap: UITapGestureRecognizer!
var pan: UIPanGestureRecognizer!
func setup() {
tap = UITapGestureRecognizer(target: self, action: #selector(Swipe.onTap))
tap.delegate = self
tap.enabled = true
self.addGestureRecognizer(tap)
pan = UIPanGestureRecognizer(target: self, action: #selector(Swipe.onPan))
pan.delegate = self
pan.enabled = true
self.addGestureRecognizer(pan)
self.backgroundColor = .blueColor()
}
func onTap() {
}
func onPan() {
}
override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
return false
}
}
即使我返回gestureRecognizerShouldBegin = false,绿色UIView也不会捕获任何事件。那么,我该如何在功能上做到这一点?求助。
答案 0 :(得分:0)
像这样交付给父母:
func onTap(tapGestureRecognizer: UITapGestureRecognizer) {
self.superview?.gestureRecognizerShouldBegin?(tapGestureRecognizer)
}