6
我有1主視圖和1個子視圖:覆蓋UIGestureRecognizer的touchesBegan
主視圖>子視圖
我認爲,主要觀點是「偷」,從子視圖的事件。
例如,當我在子視圖挖掘,只有主視圖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?
所以,問題是,我應該做的,使第二個事件(子視圖事件)太火?
在Swift中是否有像nextResponder的功能?
你介意張貼一些代碼?我無法弄清楚這個鏈接如何適合解決你的(和我的)問題。 – Suragch 2015-10-05 05:09:04