覆盖UIGestureRecognizer touches开始 [英] Override UIGestureRecognizer touchesBegan
问题描述
我有1个主视图和1个 SubView :
I have 1 Main View and 1 SubView:
主视图>子视图
我认为主视图正在窃取" SubView 中的事件.
I think that the Main View is "stealing" the events from the SubView.
例如,当我点击 SubView 时,只有 Main View GestureRecognizer 被触发.
For example, when I tap on the SubView, only the Main View GestureRecognizer is fire.
这是我的自定义 GestureRecognizer (它会拦截每个触摸事件):
Here is my custom GestureRecognizer (which intercepts every touch event):
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代码:
Maybe I should use nextResponder, but I have only found Obj-C code like:
[self.nextResponder touchesBegan:touches withEvent:event];
[self.nextResponder touchesBegan:touches withEvent:event];
问题是,我该怎么做才能使第二个事件(SubView事件)也触发?
So the question is, what should I do to make the second event (the SubView Event) fire too?
在Swift中是否有类似 nextResponder 的功能?
Is there a function like nextResponder in Swift?
推荐答案
Ôh!这是 nextResponder 的Swift代码:
Ôh ! Here is the Swift code for nextResponder :
https://stackoverflow.com/a/26510277/4135158
这篇关于覆盖UIGestureRecognizer touches开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!