2

I have many custom UIViews within a container, which I animate after the user moves them. To track their movement, I get the current position with touchesBegan:, and update the position with touchesMoved:.

Occasionally, particularly if I've moved a view very recently (and it may still be animating back to its original position), if I begin dragging another view the touchesBegan: selector will not be called, but touchesMoved: and touchesEnded: will be. How can touchesMoved: and touchesEnded: be called without touchesBegan: first being called on the view?

commanda
  • 4,841
  • 1
  • 25
  • 34
Ned
  • 6,280
  • 2
  • 30
  • 34

2 Answers2

2

I found a similar issue with my app. When I animate a view out of the way of another view, if I quickly touch the first view and start swiping, the touchesBegan event never occurs but I start getting touchesMoved once the first view has gone.

According to this answer, app starts ignores user interaction events when i call animateWithDuration:delay:options:animations:completion:, user interaction events get ignored while animating, which I think is consistent with what we're both seeing. Try using the UIViewAnimationOptionAllowUserInteraction option or userInteractionEnabled property; that should allow events through as you require.

Community
  • 1
  • 1
bw1024
  • 1,138
  • 12
  • 15
1

Probably worth re-reading the Apple docs. I'm not sure if touchesBegan is guaranteed to be called.

I'm guessing you're logging the touchesBegan etc events. Perhaps the correct events are firing but the log messages are appearing "out of order"?

SundayMonday
  • 19,147
  • 29
  • 100
  • 154
  • I thought I remembered reading that touchesBegan was guaranteed to be called, but I guess I misremembered. I am logging at each of the touch events, and when the error occurs it never logs touchesBegan. If I can't find a better solution, I'll just keep a flag to tell when touchesBegan was called, and only perform the touchesMoved and touchesEnded action when that flag is set. – Ned Mar 13 '12 at 14:09