尚未完成PAN手势状态下的触摸次数 [英] Number of touches in PAN gesture state ended is not getting in iOS

查看:56
本文介绍了尚未完成PAN手势状态下的触摸次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

当用户开始平移时,它将输入if([sender state] == UIGestureRecognizerStateBegan)和if(sender.numberOfTouches == 2),并且输入的no:of值为2.

但是,当用户结束平移时,它正在进入([sender state] == UIGestureRecognizerStateEnded)但没有迷惑if(sender.numberOfTouches == 2),并且no:of Touches的结果为0;/p>

我反复测试以确保何时用两根手指结束触摸,但结束的结果为零.

任何人都可以帮助我.请指导我出现问题的地方.

我在这一点上完全陷入困境.

 -(void)panGestureHandler:(UIPanGestureRecognizer *)发送者{如果([发件人状态] == UIGestureRecognizerStateBegan){手势_ = [[SSGesture分配] init];如果(sender.numberOfTouches == 2){startLocation = [发件人locationInView:self.view];CGPoint firstPoint = [发送者locationOfTouch:0 inView:self.imageView];initialPointOne.x = [NSString stringWithFormat:@%.0f",firstPoint.x];initialPointOne.y = [NSString stringWithFormat:@%.0f",firstPoint.y];initialPointOne.index = @"1";CGPoint secondPoint = [发件人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";pose_.initialSet = [[NSArray alloc] initWithObjects:initialPointOne,initialPointTwo,nil];}}否则,如果([[发件人状态] == UIGestureRecognizerStateEnded){NSLog(@"dsfssdf%d",sender.numberOfTouches);如果(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];pose_.finalSet = [[NSArray alloc] initWithObjects:finalPoint,finalPointTwo,nil];if([gesture_.initialSet count]&&[gesture_.finalSet count]){[使用GestureObject:gesture_和frameId:currentFrame_的[self handleGestureEventWebserviceForGesture:@"pan"];}}}} 

解决方案

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

触摸结束了,所以没有更多的手指触摸它了,对吗?在我看来,永远都是那样.

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

类似的东西:

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

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

解决方案

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];

这篇关于尚未完成PAN手势状态下的触摸次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆