iphone - 如何取消uitouches?

标签 iphone uitouch touchesbegan touchesmoved

在我的应用程序中,我想让用户点击屏幕左侧以提高速度,并在右侧滑动以操作操纵杆。但是,如果用户一直按住左侧,操纵杆将无法正常工作。

我正在使用touchesBegan、touchesMoved等。有没有办法可以取消第一次触摸的信息并单独操作操纵杆?

我已经尝试过[selftouchesCancelled:toucheswithEvent:event];还有其他方法吗?

最佳答案

Cocoa 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
    }
}

关于iphone - 如何取消uitouches?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6553343/

相关文章:

ios - 触摸并拖动 UIButton,但在松开手指时不触发它

ios - 动画阻止触摸开始

ios - 如何在 touchesBegan : and touchesEnded:? 之间以一致的方式跟踪触摸

ios - 如何缩短 "delayTouchesBegan"delays touchesBegan 的时间?

iphone - iPhone 上 Objective C 的局限性

ios - 从字符串日期获取三个字母的月份和日期?

ios - WKWebView Inside View 和 Inside ScrollView 失去联系 iOS 9

iphone - postNotificationName : called 时未发送 NSNotification

swift - 检查是否同时触及不同的 View

ios - 修复触摸在 UITableViewCell 内的 UILabel 上不起作用?