Search code examples
iphoneeventsnotificationstouchescancelled

Querying current number of touches on screen without using events on iPhone


I have an application that starts playing a sound when user touches the uiview and changing to different tones as the user slides the finger on the screen. The sound stops when the user lifts the finger.

I am using the touchesBegan, Moved and Ended Events for this.

My problem is touches Ended (and/or cancelled) is sometimes not fired properly and the sound keeps playing even after the finger is lifted from screen.

So as a workaround I would like to implement a timer that would check for the number of touches on the screen and if it is zero it will check and stop the audioplayer if playing.

I have been searching for some code that could get me the number of touches like

UITouch *touches=[self getAllTouchesonScreen];

or something :)


Solution

  • Touches Ended Event sometimes does not get fired.

    I have tried setting break points for touches cancelled and touches ended events and it sometimes doesnt hit.

    try the GLPaint sample program from Apple website and try an NSLog in toches ended and do some fast drawings on screen and lift the finger fast, like throwing the finger off screen.

    You will know what I mean. My current solution for this involves accelerometer :)

    Hint : I use this to find all events : (void)sendEvent:(UIEvent *)event