0

I have a project that I started out using a tap gesture recognizer for. I realized I didn't have enough control with the tap gesture recognizer, so I've started coding with using my viewcontroller as a UIGestureRecognizerDelegate. Just to make sure I was on the right track, I added methods for touchesBegan, touchesMoved, touchesEnded, touchesCancelled. The methods are empty except for NSLog calls so I can tell what is being fired when I try different things.

Things worked as expected except that I was getting a bunch of calls to touchesCancelled. I assume this is because of the tap gesture recognizer I still have in place. I'm not ready to remove the tap gesture recognizer, so I just wanted to confirm that this is what would happen if a gesture I used was actually a tap.

The documentation says:

This method is invoked when the Cocoa Touch framework receives a system interruption requiring cancellation of the touch event; for this, it generates a UITouch object with a phase of UITouchPhaseCancel. The interruption is something that might cause the application to be no longer active or the view to be removed from the window When an object receives a touchesCancelled:withEvent: message it should clean up any state information that was established in its touchesBegan:withEvent: implementation.

But I suspect my scenario just outlined is just as likely. Am I correct?

twernt
  • 20,271
  • 5
  • 32
  • 41
Victor Engel
  • 2,037
  • 2
  • 25
  • 46
  • You can implement `touchesBegan`, `touchesMoved`, `touchesEnded` and `touchesCancelled` without the use of a gesture recognizer. Remove the recognizer and these methods should still be called. – dasdom Dec 10 '12 at 21:17
  • Right, but that doesn't answer the question. – Victor Engel Dec 10 '12 at 21:49
  • I think what I'll do is this: Use locationInView in touchesBegan to flag the view I intend to move. In touchesMoved, I use that tag, comparing to previousLocationInView to match the touch with the view to be moved. Meanwhile, the tag is updated with the new locationInView. I continue this in touchesEnded/touchesCancelled, the last step. If in touchesEnded, I move the view. If in touchesCancelled, I clean up instead (remove the tag). – Victor Engel Dec 11 '12 at 18:17

0 Answers0