Question

Possible Duplicate:
Making use of velocityInView with UIPanGestureRecognizer

I am creating an app in which I am drawing a path based on touchMoved. I want to make the width of line based on the velocity of touch. I can achieve this effect, but there is no smoothness in this.

CODE:

-(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;
}

But i am getting something like this:

enter image description here

Was it helpful?

Solution

I have made the similar effect before. I was using the original touch event methods (touchesBegan, etc.) and calculated the velocity by myself. Every thing looks all right.

I am not sure if the velocityInView method always gives your the correct result during user moving their finger, maybe you should try to calculate the velocity by yourself and see if the problem is gone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top