The use of gestures and touches started / was moved / finished at the same time

I am trying to use swipe gestures along with some touch logic started / moved / completed. Ideally, it would be nice if:

  • User clicks left / right, touches start / move / end. Logic is not called (or canceled).
  • For all other cases, touches started / moved / finished logic is called as usual.

Is it possible?

I tried to add the following (based on the process of both the touch event and the gesture recognizer ), but for pressing move / end it is still called:

leftSwipeGestureRecognizer.delaysTouchesBegan = true self.leftSwipeGestureRecognizer.cancelsTouchesInView = false 
+7
ios swift
source share
2 answers

Must be:

 self.leftSwipeGestureRecognizer.cancelsTouchesInView = YES 

This means: the touch is canceled in case of gesture recognition, otherwise the strokes start / move / end.

From the documentation:

If this property is YES (by default), and the receiver recognizes its gesture, touches of the same gesture that are waiting are not delivered for consideration, and previously delivered touches are canceled via touchsCancelled: withEvent: message sent for viewing. If the gesture recognizer does not recognize its gesture, or if the value of this property is NO, the view receives all touches in the multi-touch Sequence.

+5
source share

In this case, I would create a custom UIGestureRecognizer for the new behavior when I click start / move / end. Useful link here . Then I set up delegate for both swipe recognition and custome and would gestureRecognizer:shouldRequireFailureOfGestureRecognizer: method to fulfill the requirements. Link to the documentation .

+1
source share

All Articles