5

I added a UIView that relied on TouchesMoved: events to drag touches. There's a long press, tap, rotate and pinch gesture recognizers already present within the same view controller. I'm running into an issue where the view receives touchesBegan: and touchesEnded: events, but no touches moved.

Is my issue with touchesMoved not being called being caused by gesture recognizers cancelling touches within the view? I also got a scroll view involved. Could that be the culprit?

If I will not be able to use touchesMoved, which is the closest gesture to implement the "touch and move" functionality. Is it tap or pan gesture recognizer?

Thank you for your help!

Alex Stone
  • 46,408
  • 55
  • 231
  • 407

2 Answers2

14

Gestures by default cancel the touches in the object they are linked to when they are active. You can stop this behavior by setting the cancelsTouchesInView property to NO.

borrrden
  • 33,256
  • 8
  • 74
  • 109
2

Mixing raw touch handling with gesture recognizers might yield strange behaviors, at least I was not able to get it working solidly, it was somewhat flaky. In your situation, you might just want to add a drag gesture recognizer (UIPanGestureRecognizer) to the view to handle the drags.

You can control the mechanism of which gesture recognizers fire in which situations by looking into gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: of UIGestureRecognizerDelegate.

Jaanus
  • 17,688
  • 15
  • 65
  • 110
  • Totally agree. Switching to gesture recognizers solved all of my problems. – Sam Soffes Aug 28 '16 at 22:48
  • I was also having trouble with a subview in a UITextField using UIResponder stuff. The text field kept stealing my touches. Gesture recognizers fixed that. – Sam Soffes Aug 28 '16 at 22:56