简体   繁体   中英

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

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

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM