13
votes

I have just discovered the Gesture Recognizers in IB and I would like to make use of them. I've tried out the Tap Gesture Recognizer however it doesn't seem to work. Here is what I've done...

  1. Dragged and dropped the 'Tap Gesture Recognizer' into my view controller in IB.

  2. Added the following method to the .m file...

    - (IBAction)viewTapped:(UIGestureRecognizer *)sender
    {
        // Do some stuff
    }
    
  3. Declared the method in the .h file...

    - (IBAction)viewTapped:(UIGestureRecognizer *)sender;
    
  4. Finally I linked up the IBAction to the 'Tap Gesture Recognizer' in IB.

When I tried running it I had no success - Have I missed something out?

3

3 Answers

23
votes

Control-click on the gesture recognizer in the nib. Under the "Referencing Outlet Collections" section of the popup, does it show any connections? It needs to be connected to the gestureRecognizers collection of your view, like this:

connections inspector

If it's not connected, drag the recognizer onto the view that you want it to be attached to. You can drag it onto the view in the design area, or you can drag it onto the view's row in the outline on the left.

6
votes

In the attributes inspector, make sure State is Enabled and 'Canceled in View' and 'Delayed Begin' events are selected.

1
votes

I was having problem with Gesture Recognizer with UIImageView. In order to get that worked, I had to check userInteractionEnabled of UIImageVIew.