Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override UIGestureRecognizer touchesBegan

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?

like image 484
Santa Claus Avatar asked Oct 22 '14 11:10

Santa Claus


1 Answers

Ôh ! Here is the Swift code for nextResponder :

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

like image 128
Santa Claus Avatar answered Oct 16 '22 00:10

Santa Claus