13

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 Answers 3

23

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.

1
  • 1
    This is just perfect but you have to drag the View in to the Gesture Recognizer, or at least that is how i could made it, not in the other way, i hope this help.
    – Stornu2
    May 30, 2014 at 11:57
6

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

1

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

1
  • Had the same problem with a regular UIView. This seems to be required. Apr 5, 2017 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.