touchesBegan: withEvent: is not called when tapped on a UIButton

ios, objective-c, uikit, uitouch

Solution

Create a subclass of UIButton and add this...

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{  
    [super touchesBegan:touches withEvent:event];
    [self.nextResponder touchesBegan:touches withEvent:event]; 
}

This will get you your touches within the button.

Problem

What I want to implement is column matching type functionality. I have three buttons on right column and three on left column with some info on them. I want to draw path from one button on right side to any of the button on left side by dragging finger. I would use `UIBezierPath` path to draw path, and for that definitely a start and end point is needed. Now the issue is how can I trigger `touchesBegan`, `touchesMoved` and `touchesEnded` methods by tapping on buttons so that I can get start and end points. Another option that I am thinking about is to cover all the buttons with an invisible UIView, and somehow check if the point touched of this overlay view lies in any of the button frames. BTW I can replace these buttons with simple UIImageView as well. I added buttons just for the sake of getting touch points. Any help.

Original source

Related problems