Override UIGestureRecognizer touchesBegan

a 夏天 提交于 2019-12-10 13:58:55

问题


I have 1 Main View and 1 SubView:

Main View > SubView

I think that the Main View is "stealing" the events from the SubView.

For example, when I tap on the SubView, only the Main View GestureRecognizer is fire.

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;
    }
}

Maybe I should use nextResponder, but I have only found Obj-C code like:

[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?

So the question is, what should I do to make the second event (the SubView Event) fire too?

Is there a function like nextResponder in Swift?


回答1:


Ôh ! Here is the Swift code for nextResponder :

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



来源:https://stackoverflow.com/questions/26506148/override-uigesturerecognizer-touchesbegan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!