0

ドキュメントから: aUIGestureRecognizerが複数のタッチを追跡している場合、 locationInView:(通常) が返されます:

... ジェスチャに含まれるタッチの重心。

私の知る限り、ジェスチャ認識機能を使用しておらず、代わりにtouchesBegan:withEvent:などを介して直接タッチを追跡している場合は、各個人UITouchtouchesそのlocationInView:.

明らかに、すべてのタッチを繰り返して重心を自分で計算できますが、これを行う iOS ライブラリ関数が必要であると推測しています。この機能にアクセスできますか? あるいは、同じ機能を得る他の方法はありますか、それとも文句を言うのをやめて自分で重心を計算するだけですか?

4

1 に答える 1

0

私の知る限り、Appleからは何も提供されていません。かなり簡単に書くと...

// returns (0,0) if touches is nil or empty
-(CGPoint) centroidOfTouches:(NSSet *)touches inView:(UIView *)view
{
    CGPoint centroid = CGPointZero, 
    curTouchPoint;
    for (UITouch *touch in touches) {
        curTouchPoint = [touch locationInView:view];
        centroid.x += curTouchPoint.x;
        centroid.y += curTouchPoint.y;
    }
    centroid.x /= [touches count];
    centroid.y /= [touches count];
    return centroid;
}
于 2013-03-28T18:10:24.643 に答える