IOS mutipletouch序列与touchesBegan和touchesEnded

时间:2012-06-27 12:07:12

标签: ios touchesbegan

这是音乐ap

用户任务是用手指1,2和3触摸并按住屏幕,触摸之间的时间很短。

如果用户按照放下的顺序(1,2,3)抬起手指,那么一切都按预期工作。所以看起来多个可以使用,用户交互等标志必须是正确的。

这是一份报告 (n是返回的触摸次数,x和y位置) (我编辑了输出文件以识别手指1,2,3

    2012-06-27 07:22:36.589 Bowing[757:907]  finger 1 Began n=0,x=190, y=860
    2012-06-27 07:22:37.207 Bowing[757:907]  finger 2 Began n=0,x=346, y=704
    2012-06-27 07:22:37.875 Bowing[757:907]  finger 3 Began n=0,x=580, y=708

    2012-06-27 07:22:38.587 Bowing[757:907]  finger 1 Ended n=0,x=191, y=854
    2012-06-27 07:22:39.252 Bowing[757:907]  finger 2 Ended n=0,x=346, y=722
    2012-06-27 07:22:40.019 Bowing[757:907]  finder 3 Ended n=0,x=585, y=712

生活是美好的

如果用户以相反的顺序(3,2,1)抬起手指,则在手指1抬起之前不会发送任何消息;然后发送所有三个手指的消息

    2012-06-27 07:22:36.589 Bowing[757:907] finger 1 Began n=0,x=190, y=860
    2012-06-27 07:22:37.207 Bowing[757:907] finger 2 Began n=0,x=346, y=704
    2012-06-27 07:22:37.875 Bowing[757:907] finger 3 Began n=0,x=580, y=708

    2012-06-27 07:22:38.587 Bowing[757:907] finger 1 Ended n=0,x=191, y=854
    2012-06-27 07:22:39.252 Bowing[757:907] finger 2 Ended n=0,x=346, y=722
    2012-06-27 07:22:40.019 Bowing[757:907] finger 3 Ended n=0,x=585, y=712

生活不是那么好。为了反映屏幕上发生的事情,消息应该已经到达手指3,手指2,然后手指1

以下是响应者;无论是否存在超级消息

,都可以正常工作
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//    [super touchesBegan:touches withEvent:event];
    NSEnumerator *enumerator = [touches objectEnumerator];
    UITouch  *aTouch;
    int counter=0;
    while ((aTouch = [enumerator nextObject])) {
        /* code that acts on the set’s values */
        CGPoint  where=[aTouch locationInView:nil];
        NSLog(@"Began n=%i,x=%3.0f, y=%3.0f",counter,where.x,where.y);
        counter++;
    }

}
// Sent to the receiver when a system event (such as a low-memory warning) cancels a touch   event.
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{

//    [super touchesCancelled:touches withEvent:event];
    NSEnumerator *enumerator = [touches objectEnumerator];
    UITouch  *aTouch;
    int counter=0;
    while ((aTouch = [enumerator nextObject])) {
        /* code that acts on the set’s values */
        CGPoint  where=[aTouch locationInView:nil];
        NSLog(@"Cancelled n=%i,x=%3.0f, y=%3.0f",counter,where.x,where.y);
        counter++;
    }

}

//当从视图或窗口抬起一个或多个手指时告诉接收者。

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
//    [super touchesEnded:touches withEvent:event];
    NSEnumerator *enumerator = [touches objectEnumerator];
    UITouch  *aTouch;
    int counter=0;
    while ((aTouch = [enumerator nextObject])) {
        /* code that acts on the set’s values */
        CGPoint  where=[aTouch locationInView:nil];
        NSLog(@"Ended n=%i,x=%3.0f, y=%3.0f",counter,where.x,where.y);
        counter++;
    }

}   

1 个答案:

答案 0 :(得分:0)

问题是: 触摸结束等待所有触摸完成,这就是为什么当它结束所有三个触摸被发送。 对此的解决方案可以是一个nstimer,它以1/32的时间间隔检测[touch count];,并检测它是增加还是减少。