iPhone UIView touchesMoved: withEvent: does not get called on UIView with gesture recognizers
Asked Answered
C

2

6

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!

Contemporary answered 26/4, 2012 at 1:30 Comment(0)
Q
15

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.

Quarrier answered 26/4, 2012 at 2:51 Comment(0)
P
3

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.

Parbuckle answered 26/4, 2012 at 3:59 Comment(2)
Totally agree. Switching to gesture recognizers solved all of my problems.Tarryn
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.Tarryn

© 2022 - 2024 — McMap. All rights reserved.