简体   繁体   中英

UIPanGestureRecognizer in iOS 4.3 not working

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?

Thanks

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

self.userInteractionEnabled = YES;

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM