Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Swipe Gesture and Touches Began/Moved/Ended at the same time

Tags:

ios

swift

I'm trying to use a swipe gesture along with some logic in touches began/moved/ended. Ideally, it would be good if:

  • User swipes left/right, touches began/moved/ended logic is not called (or cancelled).
  • For all other cases, touches began/moved/ended logic is called as usual.

Is this possible?

I tried adding the following (based on process both touch event and gesture recognizer) but touches moved/ended is still called:

leftSwipeGestureRecognizer.delaysTouchesBegan = true 
self.leftSwipeGestureRecognizer.cancelsTouchesInView = false
like image 357
HHHH Avatar asked Nov 15 '14 20:11

HHHH


2 Answers

Should be:

self.leftSwipeGestureRecognizer.cancelsTouchesInView = YES

This mean: touches are cancelled in case gesture was recognized, otherwise, touches began/moved/ended called.

From documentation:

When this property is YES (the default) and the receiver recognizes its gesture, the touches of that gesture that are pending are not delivered to the view and previously delivered touches are cancelled through a touchesCancelled:withEvent: message sent to the view. If a gesture recognizer doesn’t recognize its gesture or if the value of this property is NO, the view receives all touches in the multi-touch sequence.

like image 138
orkenstein Avatar answered Oct 20 '22 11:10

orkenstein


In this case I would create a custom UIGestureRecognizer for a new behaviour in touches began/moved/ended. Useful link here. Than I would set delegate for both swipe and custome recognizers and implement gestureRecognizer:shouldRequireFailureOfGestureRecognizer: method to fulfill requirements. Link to documentation.

like image 32
Tomasz Bąk Avatar answered Oct 20 '22 10:10

Tomasz Bąk