3

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

// 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"];
    }
}

我将如何改变它以考虑更快的加速?

4

2 回答 2

1

速度涉及时间。因此,每次您的代码运行时,您都需要在实例变量中保存事件的timestamp. 这样,下次代码运行时,您可以将翻译更改经过的时间与上一次更改进行比较。

我要做的是尝试保存三个或四个以前的时间和三个或四个以前的位置在一个数组中,以便您可以采用移动平均值并抑制速度变化。

于 2013-04-13T19:38:24.250 回答