0

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

当用户开始平移时,它将进入 if ([sender state] == UIGestureRecognizerStateBegan ) 以及 if (sender.numberOfTouches == 2) 并且我将触摸次数设为 2。

但是当用户结束它正在进入的平底锅时 ([sender state] ==UIGestureRecognizerStateEnded ) 但没有进入 if (sender.numberOfTouches == 2) 并且 end 中的 no:of Touches 给出为 0;

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

谁能帮我解决这个问题。请指导我哪里出错了。

我完全卡在了这一点上。

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

1 回答 1

0

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

触摸结束了,所以没有更多的手指在触摸它,对吧?在我看来,它将永远如此。

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

像这样的东西:

UIPanGestureRecognizer* p = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureHandler:)];
[p setMaximumNumberOfTouches:2];
[p setMinimumNumberOfTouches:2];
[yourView addGestureRecognizer:p];
于 2012-08-20T13:22:52.840 回答