我想在 Objective c 中运行动画
我正在使用 AVCaptureSession
捕捉用户照片,并在 UIImageView 上显示图像。
图像显示后,我必须运行从头顶到下巴末端的动画。
脸上共有13个点。
2在前额,
2 在鼻梁处,
2 在眼睛的尽头,
2 在每个 Nose 的开口处,
2 在嘴唇的开始和结束处,
2 在脸颊处,
1 在下巴末端
我想运行从头开始到下巴结束的动画,并从上面提到的每个点画线。 这是示例图像。
在 Objective c 中是可能的 如果是,请指导。
提前致谢。
最佳答案
使用您想要设置动画的点创建贝塞尔曲线路径,如下所示:
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 .....
用这样的路径创建一个形状图层:
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];
然后像这样为路径设置动画:
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"];
这个答案主要取自这里:
关于ios - 绘制将在 objective-c 中绘制头骨的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39659530/