【问题标题】:draw animation which will draw skull in objective c绘制动画,将在目标 c 中绘制头骨
【发布时间】:2016-09-23 11:20:48
【问题描述】:

我想在 Objective c 中运行动画

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

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

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

提前致谢。

【问题讨论】:

    标签: ios objective-c xcode animation


    【解决方案1】:

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

    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

    【讨论】:

      猜你喜欢
      • 2014-12-26
      • 2010-10-22
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-09
      • 2018-03-28
      • 1970-01-01
      相关资源
      最近更新 更多