简体   繁体   English

如何取消uitouches?

[英]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?我正在使用 touchesBegan、touchesMoved 等。有没有办法可以取消第一次触摸的信息并单独操作操纵杆?

I already tried [self touchesCancelled: touches withEvent: event];我已经尝试过[self touchesCancelled: touches withEvent: event]; is there any other way?还有其他方法吗?

The Cocoa Touch framework is multi-touch aware. Cocoa Touch 框架支持多点触控。 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
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM