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

3 つの異なる方法を試しましたが、2 ~ 5 本の指でタップできるのは 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

multipleTouchEnabledビューでプロパティをに設定しYESて、複数のUITouchオブジェクトを送信できるようにする必要があります。

UITouchそれに加えて、変更されたオブジェクトのみが渡されます。ある場所をタッチして指を動かさずに、その後別の場所をタッチすると、新しいタッチ オブジェクトのみが渡されます。UIEventビュー内のすべてのアクティブなタッチについてオブジェクトをクエリする必要があります。

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

勝利のメカニズム?使用されていないエラーや変数がありますか?

互換性のないObjective-Cタイプ'structAViewController *'、予期される'struct UIView *'異なるObjective-Cタイプから'touchesForView:'の引数1を渡す場合

AViewController.m:64:未使用の変数'touch'

于 2011-03-03T02:08:30.467 に答える