Add functionality to standard Pan Gesture Recognizer in a UIScrollView?

EDIT : this method works! You just need to set canCancelContentTouches as soon as possible (I do it in viewDidLoad ).

Up vote 0 down vote favorite share g+ share fb share tw.

I am trying to keep track of where a finger is in a UIScrollView. I have subclassed UIScrollView (see below) but unfortunately the gesture recognizer that I am adding is overriding the standard one. As a result I get NSLog(@"Pan") to work but unfortunately the view doesn't scroll anymore.

How can I get both gestures recognizers to work at the same time? Thanks. - (void)viewDidLoad:(BOOL)animated { super viewDidLoad:animated; UIPanGestureRecognizer *panRecognizer = UIPanGestureRecognizer alloc initWithTarget:self action:@selector(pan:); scrollView addGestureRecognizer:panRecognizer; } - (void)pan:(id)sender { NSLog(@"Pan"); } ios uiview uiscrollview uigesturerecognizer link|improve this question edited Dec 4 '11 at 17:59 asked Dec 4 '11 at 17:45ios-lizard717 75% accept rate.

1 You don't say what you expect to happen when both things happen at the same time. Do you expect it to scroll and update your pan recognizer? If so, why not just listen to the scroll view delegate methods that get called when the view is scrolled?

– quixoto Dec 4 '11 at 18:26 I'd like the view to both scroll and record all the points touched (that I know I can retrieve through the locationInView: method). The scroll view delegate sounds interesting -I've never heard of that... I am quite new to iOS programming-, how would that work? Thanks.

– ios-lizard Dec 4 '11 at 19:13 I have found this reference on scroll view delegates but I do not understand how to retrieve the coordinates of the touch. – ios-lizard Dec 4 '11 at 23:46.

EDIT: this method works! You just need to set canCancelContentTouches as soon as possible (I do it in viewDidLoad). ORIGINAL ANSWER: I have tried a new approach but unfortunately it doesn't fully work.

Instead of adding a gesture recognizer I am subclassing the UIScrollView and writing my own touchesBegan, touchesMoved, etc methods. This way I know where the user is touching BUT unfortunately the PanGestureRecognizer is triggering touchesCancelled every time I start to scroll even after setting the canCancelContentTouches to NO. Does anybody know why?

I have also found this.

If you want it not to override the standard one you just have to allow both to be simultaneously recognized. - (void)viewDidLoad:(BOOL)animated { super viewDidLoad:animated; UIPanGestureRecognizer *panRecognizer = UIPanGestureRecognizer alloc initWithTarget:self action:@selector(pan:); panRecognizer. Delegate = self; scrollView addGestureRecognizer:panRecognizer; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return TRUE; } - (void)pan:(id)sender { NSLog(@"Pan"); }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions