我正在创建一个应用程序,在其中我基于 touchMoved 绘制路径。我想根据触摸速度来确定线的宽度。我可以达到这个效果,但是这里面没有平滑。
代码:
-(float) clampf:(float) v: (float) min: (float) max
{
if( v < min ) v = min;
if( v > max ) v = max;
return v;
}
- (float)extractSize:(UIPanGestureRecognizer *)panGestureRecognizer
{
vel = [gesture velocityInView:self.view];
mag = sqrtf((vel.x * vel.x) + (vel.y * vel.y)); // pythagoras theorem (a(square) + b(square) = c(square))
final = mag/166.0f;
final = [self clampf:final :1 :40];
NSLog(@"%f", final);
if ([velocities count] > 1) {
final = final * 0.2f + [[velocities objectAtIndex:[velocities count] - 1] floatValue] * 0.8f;
}
[velocities addObject:[NSNumber numberWithFloat:final]];
return final;
}
但我得到这样的东西: