0

I implemeted a pan gesture in the image view.I set the number of touches as 2.

While user start to pan it will enter the if ([sender state] == UIGestureRecognizerStateBegan ) and also in if (sender.numberOfTouches == 2) and im getting the no:of touches as 2.

But when the user ended the pan it is entering ([sender state] ==UIGestureRecognizerStateEnded ) BUT not enetering into if (sender.numberOfTouches == 2) and the the no:of Touches in ended is giving as 0;

I tested again and again to make sure when the touches ended with two finger but the result for ended is zero.

Can anyone please help me with this.kindly please guide me where im going wrong.

I completely stuck at this point.

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

    if ([sender state] == UIGestureRecognizerStateBegan ) {
        gesture_ = [[SSGesture alloc]init];

        if (sender.numberOfTouches == 2) {
            startLocation = [sender locationInView:self.view];

            CGPoint firstPoint = [sender locationOfTouch:0 inView:self.imageView];
            initialPointOne.x = [NSString stringWithFormat:@"%.0f",firstPoint.x];
            initialPointOne.y = [NSString stringWithFormat:@"%.0f",firstPoint.y];
            initialPointOne.index = @"1";

            CGPoint secondPoint = [sender locationOfTouch:0 inView:self.imageView];
            SSCoordinate *initialPointTwo = [[SSCoordinate alloc]init];
            initialPointTwo.x = [NSString stringWithFormat:@"%.0f",secondPoint.x];
            initialPointTwo.y = [NSString stringWithFormat:@"%.0f",secondPoint.y];
            initialPointTwo.index = @"2";

            gesture_.initialSet = [[NSArray alloc]initWithObjects:initialPointOne,initialPointTwo, nil]; 
        }
    } else if ([sender state] ==UIGestureRecognizerStateEnded ) {
        NSLog(@"dsfssdf %d",sender.numberOfTouches);

        if (sender.numberOfTouches == 2){

            SSCoordinate *firstPoint = [gesture_.initialSet objectAtIndex:0];

            CGPoint offset = [sender translationInView:self.imageView];

            // SSCoordinate *finalPoint = [[SSCoordinate alloc]init];
            finalPoint.x = [NSString stringWithFormat:@"%.0f",[firstPoint.x floatValue] + offset.x];
            finalPoint.y = [NSString stringWithFormat:@"%.0f",[firstPoint.y floatValue] + offset.y];

            SSCoordinate *secondPoint = [gesture_.initialSet objectAtIndex:1];

            SSCoordinate *finalPointTwo = [[SSCoordinate alloc]init];
            finalPointTwo.x = [NSString stringWithFormat:@"%.0f",[secondPoint.x floatValue] + offset.x];
            finalPointTwo.y = [NSString stringWithFormat:@"%.0f",[secondPoint.y floatValue] + offset.y];

            gesture_.finalSet = [[NSArray alloc]initWithObjects:finalPoint,finalPointTwo, nil];

            if ([gesture_.initialSet count] && [gesture_.finalSet count]) {
                [self handleGestureEventWebserviceForGesture:@"pan" withGestureObject:gesture_ andframeId:currentFrame_];
            }
        } 
    }                
}
ggrana
  • 2,335
  • 2
  • 21
  • 31
suji
  • 1,470
  • 6
  • 22
  • 41

1 Answers1

0

It ended, I believe this is the expected behavior.

The touch ended so no more fingers are touching it, right ? In my point of view it will be always that way.

If you want that your event only handle events when the user touch with two finger the best option is set it in your gesture handler.

Something like that:

UIPanGestureRecognizer* p = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureHandler:)];
[p setMaximumNumberOfTouches:2];
[p setMinimumNumberOfTouches:2];
[yourView addGestureRecognizer:p];
ggrana
  • 2,335
  • 2
  • 21
  • 31
  • that i have already set UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGestureHandler:)]; panGestureRecognizer.maximumNumberOfTouches = 2; Still not effect while toches ending – suji Aug 21 '12 at 03:36
  • It will not affect the number of touches in the ending, but this will make unnecessary to test the number of touches. – ggrana Aug 21 '12 at 11:37