Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 631
iosDeveloper Avatar asked Jul 31 '13 09:07

iosDeveloper


2 Answers

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.

like image 164
Dan Avatar answered Oct 19 '22 07:10

Dan


Uncheck User Interaction Enabled checkbox of UIButton. You will get call for touchesbegan method on that button.

like image 2
Nikunj Joshi Avatar answered Oct 19 '22 06:10

Nikunj Joshi