3

I want to RUN animation in Objective c

I am capturing user photo using AVCaptureSession, and showing the image over the UIImageView. Once the image is shown, I have to RUN animation starting from Top of the head to end of chin. There are total 13 points over the face. 2 at the Forehead, 2 at the bridge of Nose, 2 at the end of the eyes, 2 at the opening of each nose, 2 at the start and ending of lips, 2 at the cheeks, 1 at chin end

I want to RUN animation which will start from head and end at chin and draw lines from each of the points mentioned above. Here is sample image like the way.

Is is possible in Objective c If yes, please guide for the same.

enter image description here

Thanks in advance.

Sagar
  • 1,286
  • 3
  • 19
  • 34

1 Answers1

1

Create bezier paths with the points you want to animate like so:

UIBezierPath *path = [UIBezierPath bezierPath];

[path moveToPoint:CGPointMake(0.0, 0.0)];

[path addLineToPoint:CGPointMake(200.0, 200.0)];
[path addLineToPoint:CGPointMake(200.0, 200.0)];
..... add all your points .....

create a shape layer with the path like this:

CAShapeLayer *bezier = [[CAShapeLayer alloc] init];

bezier.path          = bezierPath.CGPath;
bezier.strokeColor   = [UIColor blueColor].CGColor;
bezier.fillColor     = [UIColor clearColor].CGColor;
bezier.lineWidth     = 5.0;
bezier.strokeStart   = 0.0;
bezier.strokeEnd     = 1.0;
[self.view.layer addSublayer:bezier];

then animate the path like this:

CABasicAnimation *animateStrokeEnd = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animateStrokeEnd.duration  = 10.0;
animateStrokeEnd.fromValue = [NSNumber numberWithFloat:0.0f];
animateStrokeEnd.toValue   = [NSNumber numberWithFloat:1.0f];
[bezier addAnimation:animateStrokeEnd forKey:@"strokeEndAnimation"];

this answer is taken mainly from here:

Drawing animation

Community
  • 1
  • 1
ben
  • 900
  • 9
  • 17