Eksperiment626
Eksperiment626

Reputation: 1007

Xcode: Is it possible to add gesture recognizers to objects like buttons, images etc

I was wondering if it is possible to add gesture recognizers to objects like buttons, images etc.

I have used this code to create a gesture recognizer:

UITapGestureRecognizer *tapRecognizer;
tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(foundTap:)];
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.numberOfTouchesRequired = 1;

and than when I try to add the gesture I use this code:

[button addGestureRecognizer:tapRecognizer];

Problem is that it doesn't work.

Any ideas?

Thanks in advance :)

Upvotes: 2

Views: 2691

Answers (1)

Bryan
Bryan

Reputation: 12190

Your code works great for me on a UIButton, and overrides the normal action of the button.

Can you be more specific about "doesn't work"? You mean it gives an error? Or you see no callback?

If the latter, how did you declare the method 'foundTap:' ?

Upvotes: 3

Related Questions