Question

I need to track where the touches are while the user pinches to do some fancy bits and pieces, for a game, unrelated to zooming. I can detect pinches but I can't find the location of the taps during the pinch, only the midpoint (even using the private variable touches doesn't work).

An ideal outcome would be (where Box2DPinchRecognizer is the name of my UIPinchRecognizer subclass):

Box2DPinchRecognizer *pinchRecognizer = [[Box2DPinchRecognizer alloc] initWithTarget:self action:@selector(pinchGesture:) withObject:(NSArray*)touches];

Where touches is an array of the two CGPoints indicating where your fingers are.

Was it helpful?

Solution

No need to subclass anything. You should be able to ask any UIGestureRecognizer for the location of its current touches in its action method:

- (void)pinchGesture:(UIGestureRecognizer *)recognizer
{
    NSUInteger numberOfTouches = recognizer.numberOfTouches;
    NSMutableArray *touchLocations = [NSMutableArray arrayWithCapacity:numberOfTouches];
    for (NSInteger touchIndex = 0; touchIndex < numberOfTouches; touchIndex++) {
        CGPoint location = [recognizer locationOfTouch:touchIndex inView:self.view];
        [touchLocations addObject:[NSValue valueWithCGPoint:location]];
    }
    ...
}


Edit:
At the end of code square bracket is added.

OTHER TIPS

The first part of my custom UIPinchGestureRecognizer gives you the locations of both touches. Maybe it can help: https://stackoverflow.com/a/17938469/1186235

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top