Tuesday, July 27, 2010

double tap

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));
}

No comments:

FEEDJIT Live