Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate a point of a Bezier curve [duplicate]

Is is possible to animate a point of a bezier curve? I am trying make a smooth transition from a line to an arrow.

Animate Bezier Point

Here's what the line looks like in code

//// Color Declarations
UIColor* white = [UIColor colorWithRed: 1 green: 1 blue: 1 alpha: 0.374];

//// Group
{
    //// Bezier Drawing
    UIBezierPath* bezierPath = [UIBezierPath bezierPath];
    [bezierPath moveToPoint: CGPointMake(30.5, 43.5)];
    [bezierPath addLineToPoint: CGPointMake(30.5, 29.59)];
    [bezierPath addLineToPoint: CGPointMake(30.5, 15.5)];
    bezierPath.lineCapStyle = kCGLineCapRound;

    bezierPath.lineJoinStyle = kCGLineJoinBevel;

    [white setStroke];
    bezierPath.lineWidth = 5.5;
    [bezierPath stroke];
}

... however I do not know how to pick a point and animate just that. Is this even possible?

like image 910
Bernd Avatar asked Sep 13 '13 19:09

Bernd


1 Answers

Explicit CGPath animation using a CAShapeLayer:

// Create the starting path. Your curved line.
UIBezierPath * startPath; 
// Create the end path. Your straight line.
UIBezierPath * endPath; 

// Create the shape layer to display and animate the line.
CAShapeLayer * myLineShapeLayer = [[CAShapeLayer alloc] init];

CABasicAnimation * pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
pathAnimation.fromValue = (__bridge id)[startPath CGPath];
pathAnimation.toValue = (__bridge id)[endPath CGPath];
pathAnimation.duration = 5.0f;
[myLineShapeLayer addAnimation:pathAnimation forKey:@"animationKey"];
like image 175
Guelph Avatar answered Oct 17 '22 01:10

Guelph