覆盖UIGestureRecognizer touchesBegan

时间:2014-10-22 11:13:19

标签: swift override touch-event

我有1个主视图和1个子视图

主视图>子视图

我认为主视图是"偷窃"来自 SubView 的事件。

例如,当我点击 SubView 时,只会触发主视图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?

     

Is there a way to pass touches through on the iPhone?

所以问题是,我该怎样做才能使第二个事件(SubView事件)发生火灾?

Swift中是否有像 nextResponder 这样的功能?

1 个答案:

答案 0 :(得分:1)

Ôh!以下是 nextResponder 的Swift代码:

https://stackoverflow.com/a/26510277/4135158