私は持っています:
UITouch *touch = [touches anyObject];
if ([touches count] == 2) {
//preforming actions
}
私がやりたいのはif
、2つのタッチが別々になっているステートメントの中でそれを尋ねることです。
私は持っています:
UITouch *touch = [touches anyObject];
if ([touches count] == 2) {
//preforming actions
}
私がやりたいのはif
、2つのタッチが別々になっているステートメントの中でそれを尋ねることです。
タッチを繰り返すことができます:
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));
}
Touchesはすでに配列です。それらを別の配列にコピーする必要はありません。[touchesobjectAtIndex:n]を使用してtouchnにアクセスするだけです。