Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIGestureRecognizer - detecting tap and drag like trackpad

Is there any way to cascade UIGestureRecognizers to detect a tap and then drag. For example, I want to detect when the user taps and then drags his finger around.

This would be similar how drag works on trackpads.

So I want to detect a tap, then I want to get UIPanGestureRecognizer to send me continuous updates.

I want to use standard UIGesture classes to create this new gesture instead of creating my own using raw touches.

Is this even possible?

like image 562
Tom Dev Avatar asked Mar 10 '11 13:03

Tom Dev


1 Answers

although i haven't found the solution the way i expected, i found a better solution.

By just using UILongPressGrstureRecognizer, it is surprising that it is able to implement tap and drag.

You have to:

  1. set the numberOfTapsRequired to 1 to detect the initial tap.
  2. set the minimumDuration something smaller to detect drags quicker without waiting

e.g.:

UILongPressGestureRecognizer *mouseDrag = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleDrag:)];
mouseDrag.numberOfTapsRequired=1;
mouseDrag.minimumPressDuration=0.05;
[clickLeft requireGestureRecognizerToFail:mouseDrag];

to handle the drag, you must determine the state to handle it appropriately as a continuous gesture.

like image 153
Tom Dev Avatar answered Oct 20 '22 00:10

Tom Dev