使用 performSelector:withObject:afterDelay: 递归调用 refreshLabels 怎么样?
当手势结束时,设置一个私有计数器并调用 refreshLabels。在 refreshLabels 中,使用计数器作为“所用时间”变量计算简单的减速曲线,并将结果值用作下一次递归调用的延迟。
示例代码:
int counter; // Set this value to 1 when the gesture completes
- (void)refreshLabels:(id)sender{
// Update the labels using whatever code you have
// This code will execute the recursive deceleration
if (counter > -1){
float somereasonablenumber = 0.1F;
float delaytime = (1.0-0.1)/counter; // deceleration = (finaltime-initialtime)/timetaken
counter++;
if (delaytime > somereasonablenumber){
[self performSelector:@selector(refreshLabels:) withObject:nil afterDelay:delaytime];
} else {
counter = -1;
}
}
}
您可能需要使用我用于 finaltime 和 initialtime 的值来获得您想要的曲线。现在,此代码将在延迟曲线上执行,例如:
0.9s
0.45s
0.3s
0.225s
0.18s
0.15s
0.128571429s
0.1125s