1

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.

glenstorey
  • 5,134
  • 5
  • 39
  • 71

2 Answers2

3

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.

Ikrom
  • 4,785
  • 5
  • 52
  • 76
Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
  • 1
    Note that I don't know if the order of the touches will be the same (i.e., if one touch always has the same index as long as it doesn't stop) on every execution of the method. I'd be interested to know if this is the case. – Ole Begemann Apr 16 '12 at 09:50
0

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

Community
  • 1
  • 1
Scott
  • 652
  • 1
  • 7
  • 15