Second touch after UILongPressGestureRecognizer has began
I'm using UILongPressGestureRecognizer
and when I use one finger it works properly. When I lay down a second finger this is not captured by the recognizer, the delegate
keeps being called but only with the first touch, [recognizer numberOfTouches]
is always 1.
If I set [recognizer setNumberOfTouchesRequired:2]
it also works properly, I get [recognize开发者_Go百科r numberOfTouches]
= 2 when I lay 2 fingers down simultaneouly.
My conclusion is: after a UILongPressGesture
is recognized and began, a second touch won't change it. Is this the expected behaviour?
You could add two different UILongPressGestureRecognizers, one set up with numberOfTouchesRequired
= 1, and one = 2.
You also probably want the one that only expects for 1 finger to fail if it recognizes the other one (in case the user taps with one finger, and inmediately after puts down another finger).
It would be something like this:
UILongPressGestureRecognizer *oneFingerLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerLongPressed:)];
oneFingerLongPressGesture.numberOfTouchesRequired = 1;
UILongPressGestureRecognizer *twoFingersLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersLongPressed:)];
twoFingersLongPressGesture.numberOfTouchesRequired = 2;
[oneFingerLongPressGesture requireGestureRecognizerToFail:twoFingersLongPressGesture];
UIView *someView;
[someView addGestureRecognizer:oneFingerLongPressGesture];
[someView addGestureRecognizer:twoFingersLongPressGesture];
[oneFingerLongPressGesture release];
[twoFingersLongPressGesture release];
精彩评论