How to cancel uitouches?

In my application, I want users to touch the left side of the screen to increase speed and swipe on the right side to work with the joystick. However, if the user holds the left side, the joystick does not work correctly.

I use touchhesBegan, touchhesMoved etc. Is there a way that I could cancel the information from the first touch and execute the joystick separately?

I already tried [self touchesCancelled: touches withEvent: event]; Is there another way?

+4
source share
1 answer

Cocoa Touch interface supports multi-touch. Therefore, you do not need to cancel the first touch to work with the second touch. Just list the strokes and use only the one you want for the joystick in your touch delegate.

 NSArray *allTouches = [ touches allObjects ]; int numTouches = [ allTouches count ]; for (int i=0; i<numTouches; i++) { UITouch *theTouch = [ allTouches objectAtIndex:i ]; if (theTouch != leftSideHoldTouch) { // maybe it a joystick touch, so handle it here } } 
+3
source

All Articles