繁体   English   中英

如何检查平移手势未移动

[英]How to check Pan gesture Not Moved

我查看了从一个位置到另一个位置的视图。 我可以在移动时获得点的位置,但是我想在平移未移动或在某一点空闲时执行某些操作。 我没有看到任何状态显示平移手势是空闲的。 我遇到的触摸事件是UITouchPhaseStationary坚果我不知道如何实现它。

没有一个国家是什么,以及UITouchPhaseStationary在解释这个帖子是支持多点触控,并让你知道,如果有在屏幕上的第二个动的手指,而另一根手指移动。

但是,您可以自己实现这样的功能。 只需将时间间隔设置为超时的定时器,然后应将触摸视为静止,并在手势位置发生变化时运行。 当手势结束时以及手势改变以重置计时器时,您将希望使计时器无效。 这是一个例子。

- (void)gestureDidFire:(UIPanGestureRecognizer *)gesture
{
    static NSTimer *timer = nil;

    if (gesture.state == UIGestureRecognizerStateChanged) {
        if (timer.isValid) {
            [timer invalidate];
        }

        timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerDidFire:) userInfo:nil repeats:NO];

    }else if (gesture.state == UIGestureRecognizerStateEnded) {
        if (timer.isValid) {
            [timer invalidate];
        }
    }
}

- (void)timerDidFire:(NSTimer *)timer
{
    NSLog(@"Stationary");
}

你可以实现touchesEnded:withEvent:来确定触摸何时完成。 在panGesture方法上设置一个标志,然后检查该值

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    if (self.hasMoved) {
       // Do something
       self.hasMoved = NO;
    }
}

尝试这个

    - (void)panRecognized:(UIPanGestureRecognizer *)rec
    {
    CGPoint vel = [rec velocityInView:self.view];
     if (vel.x == 0 && vel.y == 0)
     {
       // Not moved
     }
     else
              // moved
    } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM