PAN手势状态结束的触摸次数未在iOS中获得

时间:2012-08-20 12:56:18

标签: iphone objective-c

我在图像视图中实现了平移手势。我将触摸次数设置为2。

当用户开始平移时,它将输入if([sender state] == UIGestureRecognizerStateBegan)以及if(sender.numberOfTouches == 2)并且我将no:of touches输入为2。

但是当用户结束平移时它正在进入([发送者状态] == UIGestureRecognizerStateEnded)但是没有进入if(sender.numberOfTouches == 2)并且结束时的结束的no:给出为0; < / p>

我一次又一次地测试,以确保触摸以两根手指结束,但结果为零。

任何人都可以帮我解决这个问题。请指导我哪里出错。

我完全陷入了困境。

- (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_];
            }
        } 
    }                
}

1 个答案:

答案 0 :(得分:0)

结束了,我相信这是预期的行为。

触摸结束,所以没有手指触摸它,对吗?在我看来,它总是那样。

如果您希望事件仅在用户用两根手指触摸时处理事件,则在手势处理程序中设置最佳选项。

类似的东西:

UIPanGestureRecognizer* p = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureHandler:)];
[p setMaximumNumberOfTouches:2];
[p setMinimumNumberOfTouches:2];
[yourView addGestureRecognizer:p];