我需要检测两个手指触摸事件。如果我同时用两个手指触摸屏幕,那么一切都正常。只需使用以下代码:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[touches allObjects] objectAtIndex:0];
CGPoint point1 = [touch locationInView:self];
CGPoint point2 ;
NSLog(@"First: %f %f", point1.x, point1.y) ;
if ([[touches allObjects] count] > 1) {
UITouch *touch2 = [[touches allObjects] objectAtIndex:1];
point2 = [touch2 locationInView:self];
NSLog(@"Second: %f %f", point2.x, point2.y) ;
}
}
但是如果我用一根手指按住屏幕,然后用另一根手指触摸屏幕时,这段代码就不起作用了。如何实现这个功能?难度大吗?
touchesForView:self
更改为touchesForView:self.view
。 - akaru