Take the 2-minute tour ×

I have a UIImageView subclass and I need to have a pan gesture so I added the following code:

UIPanGestureRecognizer * panRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan)];
[self addGestureRecognizer:panRecognizer];

but my handlePan selector never gets called.

Is there something else i need to do?


share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

If your object is UIImageView subclass, you have to enable user interaction. It is set to NO by default for UIImageView.

self.userInteractionEnabled = YES;
share|improve this answer
OMG, YES, I remember reading about that... thank you, thank you, that worked!!! –  LilMoke Mar 28 '12 at 11:40
You are welcome! I have faced this problem several times :) Please check my answer as correct to close this issue. –  Martin Pilch Mar 28 '12 at 11:47
Yes, I tried to accept it, but it told me I had to wait 5 minutes... geez your fast, please answer all my questions!!! -:) –  LilMoke Mar 28 '12 at 11:48
I get it, no problem :) I will try it –  Martin Pilch Mar 28 '12 at 11:50
add comment

I had EXACTLY the same problem using the StoryBoard - I created a sub-view in my main view, dropped a Pan Gesture Recognizer on it, created an action and joined the pan to it, and it didn't work.

My sub-view had User Interaction Enabled on it and it didn't work. Frustrated, I deleted my Pan Gesture, added it back, everything seemed hooked up and it still didn't work.

Finally, I looked at the SUPERVIEW and its User Interaction Enabled was checked off. Checking it on and it worked.

So as a caveat, if it's not working, look at the parent views too!

share|improve this answer
add comment

Your Answer


