Ios 如何检测平移手势何时真正快速移动,而不是精细移动,从而相应地调整控制?

Ios 如何检测平移手势何时真正快速移动,而不是精细移动,从而相应地调整控制?,ios,objective-c,uigesturerecognizer,uipangesturerecognizer,Ios,Objective C,Uigesturerecognizer,Uipangesturerecognizer,在我的应用程序中,我可以选择让用户向上平移来调整控件,但当他们向上平移的速度非常快时,速度会有点慢,我想跳得更多 // If user is panning upwards or downwards, adjust WPM every 8 translations in either direction if (translation.y<-8 || translation.y>8) { // Reset translation so we can see when it e

在我的应用程序中,我可以选择让用户向上平移来调整控件,但当他们向上平移的速度非常快时,速度会有点慢,我想跳得更多

// If user is panning upwards or downwards, adjust WPM every 8 translations in either direction
if (translation.y<-8 || translation.y>8) {
    // Reset translation so we can see when it exceeds 8 again
    [recognizer setTranslation:CGPointMake(0, 0) inView:self.view];

    // Figure out direction, if pan down, decrease by 5, if up, increase by 5
    int sign = (translation.y > 0) ? -1 : 1;
    WPM = @([WPM intValue] + (sign * 5));

    if ([WPM intValue] >= 200 && [WPM intValue] <= 1500) {
        self.WPMLabel.text = [WPM stringValue];

        self.wordsPerMinute = WPM;

        [[NSUserDefaults standardUserDefaults] setObject:WPM forKey:@"WPM"];
    }
}
//如果用户向上或向下平移,则在任意方向上每8次平移调整一次WPM
如果(翻译为y8){
//重置转换,以便我们可以看到它何时再次超过8
[识别器setTranslation:CGPointMake(0,0)inView:self.view];
//算出方向,向下平移减少5,向上平移增加5
整数符号=(平移.y>0)?-1:1;
WPM=@([WPM intValue]+(符号*5));

如果([WPM intValue]>=200&&[WPM intValue]速度涉及时间。因此,每次代码运行时,您都需要在实例变量中保存事件的
时间戳上的时间。这样,下次代码运行时,您就可以比较转换更改和经过的时间与以前的更改


我要做的是尝试在一个数组中保存三到四次之前的时间和三到四个之前的位置,这样您就可以获得移动平均值并消除速度变化。

使用手势识别器上的速度属性


如何获取事件的时间戳?最准确的方法是:编写一个UIPangestureRecognitizer子类来完成这一切。现在,您可以检查实际的触摸,它有一个时间戳。-您可以根据每次调用的时间来计算算法,但这不如触摸时间戳准确,触摸时间戳告诉您事件实际发生的时间。