3
votes

I'm using TouchesBegan TouchesMoved with Multitouch.

I have a manual implementation of what is essentially a button.

I bounds test on the point of TouchesBegan to set the button as down and the same for TouchesEnded to reset it.

The problem is if the user moves the finger out of the bounds of the button before lifting then the TouchesEnded is outside of the bounds of the button where the touch started.

I can't just reset everything on touchesended as the user might still be holding another button down with another finger.

What is the recommended solution to this? UIButton must be doing something similar somehow.

1
What do you mean by reseting everything? Does your button class hold the touching state {isTouched, isReleased}, or other "controller" hold the touching state? - AZ.
@AZ I have a flag which tracks when my "button" is down or not. I could use TouchesEnded to reset all the flags (on all buttons) but then people couldn't hold one button down whilst releasing another - acheo

1 Answers

3
votes

You need to watch touchesMoved: and "deactivate" your button when the touch moves outside of its bounds, and "reactivate" your button when the touch moves back in. See Handling a Complex Multi-Touch Sequences for explanation of how to watch for mutations on a multi-touch sequence (fancy way of saying "which finger was that?")