1

这是启用了多个触摸的视图的 touchesBegan 方法。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch* touch = [touches anyObject];
    if ([touches count] > 1)
        NSLog(@"multi touches: %d fingers", [touches count]);

    NSUInteger numTaps = [touch tapCount];

    if (numTaps == 1) {
        NSLog(@"single tap");
    } else {
        NSLog(@"multi tap: %d", numTaps);
    }
}

我似乎从来没有记录过多点触控。只需单击和双击。我认为它就像获得触摸计数一样容易,我错了吗?

4

3 回答 3

1

您应该在视图上设置multipleTouchEnabled属性以YES让它向您发送多个UITouch对象。

除此之外,仅UITouch传递更改的对象。如果您触摸某个位置并且不移动手指,然后再触摸另一个位置,则只会传递新的触摸对象。您应该查询UIEvent视图中所有活动触摸的对象:

[event touchesForView:self]
于 2009-09-06T03:22:14.893 回答
1

我尝试了三种不同的方法,只有一种可以返回两到五个手指轻敲。中奖机制为 NSSet *touch = [event allTouches];

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch* touch = [touches anyObject];
    // the next line will not ever return a multiple tap
    if ([touches count] > 1)
        NSLog(@"multi-touches %d", [touches count]);
    // the next line will return up to 5 (verified) simultaneous taps (maybe more)
        NSSet *touch2 = [event allTouches];
    if ([touch2 count] > 1)
        NSLog(@"multi-touches2 %d", [touch2 count]);
    // the next line only returns 1 tap
        NSSet *touch3 = [event touchesForView:self];
    if ([touch3 count] > 1)
        NSLog(@"multi-touches2 %d", [touch3 count]);
}
于 2009-09-10T11:53:57.417 回答
-1

制胜机制?甚至没有使用的错误和变量?

不兼容的 Objective-C 类型“struct AViewController *”,当从不同的 Objective-C 类型传递“touchesForView:”的参数 1 时,预期为“struct UIView *”

AViewController.m:64: 未使用的变量“触摸”

于 2011-03-03T02:08:30.467 回答