0

私は持っています:

UITouch *touch = [touches anyObject];

    if ([touches count] == 2) {
        //preforming actions                                                             
    }

私がやりたいのはif、2つのタッチが別々になっているステートメントの中でそれを尋ねることです。

4

2 に答える 2

1

タッチを繰り返すことができます:

if([touches count] == 2) {
    for(UITouch *aTouch in touches) {
        // Do something with each individual touch (e.g. find its location)
    }
}

編集:たとえば、2つのタッチ間の距離を見つけたい場合で、正確に2つあることがわかっている場合は、それぞれを個別に取得してから、計算を行うことができます。例:

float distance;
if([touches count] == 2) {
    // Order touches so they're accessible separately
    NSMutableArray *touchesArray = [[[NSMutableArray alloc] 
                                     initWithCapacity:2] autorelease];
    for(UITouch *aTouch in touches) {
        [touchesArray addObject:aTouch];
    }
    UITouch *firstTouch = [touchesArray objectAtIndex:0];
    UITouch *secondTouch = [touchesArray objectAtIndex:1];

    // Do math
    CGPoint firstPoint = [firstTouch locationInView:[firstTouch view]];
    CGPoint secondPoint = [secondTouch locationInView:[secondTouch view]];
    distance = sqrtf((firstPoint.x - secondPoint.x) * 
                     (firstPoint.x - secondPoint.x) + 
                     (firstPoint.y - secondPoint.y) * 
                     (firstPoint.y - secondPoint.y));
}
于 2009-12-29T18:12:14.133 に答える
-1

Touchesはすでに配列です。それらを別の配列にコピーする必要はありません。[touchesobjectAtIndex:n]を使用してtouchnにアクセスするだけです。

于 2010-05-04T12:39:11.073 に答える