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