【发布时间】:2014-03-02 12:19:58
【问题描述】:
我一直在尝试识别 iOS 应用程序中的触摸,我有这个简单的代码
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"%lu",(unsigned long)[touches count]);
[touches enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
UITouch *touch = obj;
CGPoint touchLocation = [touch locationInNode:self.scene];
NSLog(@"B x:%f - y:%f",touchLocation.x,touchLocation.y);
}];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[touches enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
UITouch *touch = obj;
CGPoint touchLocation = [touch locationInNode:self.scene];
NSLog(@"E x:%f - y:%f",touchLocation.x,touchLocation.y);
}];
}
touchesBegan 的调用很好,如果我同时将 1 根手指到 5 根手指放在屏幕上,我会看到它被正确的信息调用
touchesBegan 不会发生同样的情况,很多时候如果我在屏幕上有 3 根手指并同时移除它们,我只会看到关于 2 次触摸结束的信息(有时甚至是 1 次)。如果我一次取出一根手指,该方法通常也会被调用 2 次(有时 1 次,但很少会被正确调用 3 次)
随着触摸次数的增加,touchesEnded 方法中也可能不会显示某些信息
方法touchesMoved:withEvent:和touchesCancelled:withEvent:也实现了,逻辑相同
有人可以解释这种行为吗?我有什么遗漏吗?
【问题讨论】:
-
您解决了这个问题吗?
-
有公认的答案吗?
标签: ios multi-touch