Simultaneous use of touch and touch gesture recognizers

I use two gesture recognizers on my UIView . One of them is a standard UITapGestureRecognizer , the other is a very simple touch recognizer that I wrote:

 @implementation TouchDownGestureRecognizer - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if (self.state == UIGestureRecognizerStatePossible) { self.state = UIGestureRecognizerStateRecognized; } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { self.state = UIGestureRecognizerStateFailed; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { self.state = UIGestureRecognizerStateFailed; } @end 

They work together only if I assign a delegate to both of them that contains this method:

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; } 

Everything works fine, but when I press this point for a long time, touch the recognition lights and touch the recognizer. For short taps everything is in order, they both shoot.

I implemented all the methods in UIGestureRecognizerDelegate to return YES to no avail. If I add logging to see the interaction with the delegate and inside my own recognizer, I see that for short and long taps the call sequence is identical - except for the call to direct the recognizer. What am I doing wrong?

+4
source share
1 answer

Why don't you just check touchUp directly from UILongPressGestureRecognizer ?

 -(void)selectionDetected:(UILongPressGestureRecognizer*)longPress { if(longPress.state==1) { //long Press is being held down } else if(longPress.state==3) { //the touch has been picked up } } 
+6
source

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


All Articles