我在图像视图中实现了平移手势。我将触摸次数设置为 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_];
}
}
}
}