【发布时间】:2014-10-22 11:13:19
【问题描述】:
我有 1 个主视图和 1 个子视图:
主视图 > 子视图
我认为主视图正在“窃取”来自 SubView 的事件。
例如,当我点击 SubView 时,只有 Main View GestureRecognizer 会触发。
这是我的自定义 GestureRecognizer(拦截每个触摸事件):
import UIKit
import UIKit.UIGestureRecognizerSubclass
class MainGestureRecognizer: UIGestureRecognizer {
override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {
super.touchesBegan(touches, withEvent: event);
//nextResponder() ??
state = UIGestureRecognizerState.Began;
}
override func touchesMoved(touches: NSSet!, withEvent event: UIEvent!) {
super.touchesMoved(touches, withEvent: event);
//nextResponder() ??
state = UIGestureRecognizerState.Changed;
}
override func touchesEnded(touches: NSSet!, withEvent event: UIEvent!) {
super.touchesEnded(touches, withEvent: event);
//nextResponder() ??
state = UIGestureRecognizerState.Ended;
}
override func touchesCancelled(touches: NSSet!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event);
//nextResponder() ??
state = UIGestureRecognizerState.Cancelled;
}
}
也许我应该使用 nextResponder,但我只找到了 Obj-C 代码,例如:
[self.nextResponder touchesBegan:touches withEvent:event];
What's the trick to pass an event to the next responder in the responder chain?
所以问题是,我应该怎么做才能让第二个事件(SubView 事件)也触发?
在 Swift 中有没有类似 nextResponder 的函数?
【问题讨论】:
标签: swift overriding touch-event