Little trouble with pan gesture: iPhone

Adding Pan Gesture on UIView is straightforward. No tutorial on gestures but another silly mistake that was ignored. I had a class that extended UIView. I had my custom initializer method. I was doing some quick experiment for my prototype. So story is small part of that experiment, I created one instance of my class and added few UIImageView within it. I added the pan gesture to my view class. Some beautiful pictures were displayed but the selector that was supposed to be called for pan gesture wasn’t been called at all.

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

One primary reason could be that userInteractionEnabled was set off. I set it to YES but still same. I added above same gesture to UIImageView that was residing within my main UIView and it was calling gesture selector. So what was wrong with my UIView class? I had done this many times before and never gave such issue.

I think I realized my grave silly mistake after hour. It was really a silly mistake from my side. It was with my initialization. Here was my initialization code:

PGeneralView * view = [[PGeneralView alloc] init];

After init, I added subviews. Can you see the problem? Problem is I haven’t specified any frame dimension for my main uiview, hence no interaction. After this realization I was thinking getting high and go out 😀

Be the first to leave a comment. Don’t be shy.

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>