ios - 绘制将在 objective-c 中绘制头骨的动画

标签 ios objective-c xcode animation

我想在 Objective c 中运行动画

我正在使用 AVCaptureSession 捕捉用户照片,并在 UIImageView 上显示图像。 图像显示后,我必须运行从头顶到下巴末端的动画。 脸上共有13个点。 2在前额, 2 在鼻梁处, 2 在眼睛的尽头, 2 在每个 Nose 的开口处, 2 在嘴唇的开始和结束处, 2 在脸颊处, 1 在下巴末端

我想运行从头开始到下巴结束的动画,并从上面提到的每个点画线。 这是示例图像。

在 Objective c 中是可能的 如果是,请指导。

enter image description here

提前致谢。

最佳答案

使用您想要设置动画的点创建贝塞尔曲线路径,如下所示:

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"];

这个答案主要取自这里:

Drawing animation

关于ios - 绘制将在 objective-c 中绘制头骨的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39659530/

相关文章:

iphone - 在 iPhone 上绕过 socks 代理配置

ios - cocoa pod 的问题

ios - masksToBounds 与 clipsToBounds

ios - 下载FTP目录内容到ios

ios - 每个国家的城市列表及其位置信息

iOS计时器/工资计算器

ios - 与 iPhone SDK 中的 session 相比,Flurry 日志事件更新相当晚

ios - NavigationBar tintColor 不影响文本颜色

iOS自定义键盘加载问题

iphone - 获取时核心数据中的重复记录