在我的应用程序中,我想检测用户何时抬起他的第二根手指并且只在屏幕上按住一根手指。
问题是我的 touchesEnded:withEvent: 显示 [[event allTouches] count] 为 2。
如何检测屏幕上保留了哪一个触摸?
谢谢。
当触摸由用户 touchesBegan 方法触发时。您可以保持指针在第一次触摸时出现。在触摸结束之前不会更改。
编辑:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([touches count] == 1)
{
if (!myTouch) myTouch = [touches anyObject]; //I assume myTouch is set to nil in touchesEnded
}
else
{
//perform your logic for this case
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if ( myTouch && [touches containsObject: myTouch]
{
//perform your logic
myTouch = nil;
}
}
我假设您UITouch *myTouch
的类中有一个处理触摸事件的变量。