Second touch after starting UILongPressGestureRecognizer

I use UILongPressGestureRecognizer, and when I use one finger, it works correctly. When I put the second finger, it is not captured by the recognizer, it delegatecontinues to be called, but only with the first touch it is [recognizer numberOfTouches]always 1.

If I install [recognizer setNumberOfTouchesRequired:2], it also works correctly, I get [recognizer numberOfTouches]= 2 when I put two fingers at the same time.

My conclusion: after it is UILongPressGesturerecognized and starts, the second touch will not change it. Is this expected behavior?

+3
source share
1 answer

UILongPressGestureRecognizers, numberOfTouchesRequired= 1 one = 2. , , , ( ).

:

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];
0

Source: https://habr.com/ru/post/1761927/


All Articles