UIPanGestureRecognizer receives cords of all strokes

I added the following gesture recognizer:

UIPanGestureRecognizer *d2 = [[UIPanGestureRecognizer alloc] 
                              initWithTarget:self 
                              action:@selector(ViewDragging2:)];
[d2 setMinimumNumberOfTouches:2];
[d2 setMaximumNumberOfTouches:2];
[targetView addGestureRecognizer:d2];

and the method that runs when this event occurs is as follows:

-(void)ViewDragging2:(UIPanGestureRecognizer*)sender {

    // some point
    CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:targetView];
}

which give me one touch, although I touch with two fingers. How can I get the first and second touch cords?

+3
source share
2 answers

You can access all the touches using the following methods:

  • (NSUInteger)numberOfTouches
  • (CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view

They are defined in the base class, UIGestureRecognizer .

+8
source

Try using the following code.

UIPanGestureRecognizer *d2 = [[UIPanGestureRecognizer alloc] 
                          initWithTarget:self 
                          action:@selector(ViewDragging2:)];
  [d2 setMinimumNumberOfTouches:2];
  [d2 setMaximumNumberOfTouches:2];
 [targetView addGestureRecognizer:d2];

and the method that runs when this event occurs is as follows:

   -(void)ViewDragging2:(UIPanGestureRecognizer*)sender
    {
      // where touchIndex is either 0 or 1.
       CGPoint location = [recognizer locationOfTouch:touchIndex inView:self.view];
   }

check this link locationOfTouch and numberOfTouches

Regards, Neil.

+4
source

All Articles