Georges Oates Larsen Georges Oates Larsen - 4 months ago 43
iOS Question

Simulating drags inside a scrollview

:) I am working on intercepting, and resending gestures sent to a scrollview.

What I want to do:

Kill all gestureRecognizers in the scrollview. I have accomplished this.

Add new gestureRecognizers in the scrollview. I have accomplished this as well.

Make the new recognizers behave the same as the old ones. I have NOT accomplished this, and I need help doing so.

The only new recognizer I have added is a pan gesture recognizer, which requires at least two fingers. I want this to behave exactly as a one finger scroll. :)

What kind of calls must I send when responding to the callbacks generated by the new recognizer to accomplish this?


I think you've overcomplicated this by trying to implement your own custom gesture recogniser.

The UIPanGestureRecognizer class has a minimumNumberOfTouches property which you should be able to set to 2 for your UIScrollView.

To do so just grab your views gesture recognisers...


Iterate over the array to find the pan gesture...

if ([gestureRecogniser isKindOfClass:[UIPanGestureRecognizer class]])

Cast your gestureRecogniser pointer to the more specific type...

UIPanGestureRecognizer *panGestureRecogniser = (UIPanGestureRecognizer *)gestureRecogniser;

And finally set its minimumNumberOfTouches property...

panGestureRecogniser.minimumNumberOfTouches = 2;

The only other thing you may have to do is enabled multitouch for your view - UIView has a multipleTouchEnabled property that should be set to true.