开发者

How to cancel uitouches?

In my app I want to have the users tap on the left side of the screen to increase their speed and swipe on the right side to work a joystick. However, if the user keeps holding the left side, the joystick doesn't work right.

I am using touchesBegan, touchesMoved, etc. Is there a way I could cancel the info from the first touch and have do the joystick separately?

I already tried [self touchesCancelled: touches withEvent: event];开发者_开发问答 is there any other way?


The Cocoa Touch framework is multi-touch aware. Therefore you don't have to cancel the first touch to work with the second touch. Just enumerate the touches 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's a joystick touch, so handle it here
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜