码迷,mamicode.com
首页 > 其他好文 > 详细

用CAShapeLayer和UIBezierPath和CABaseAnimation制作动画折线图

时间:2015-02-05 21:42:47      阅读:679      评论:0      收藏:0      [点我收藏+]

标签:

 // 创建layer并设置属性
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.fillColor = [UIColor clearColor].CGColor;
    layer.lineWidth =  2.0f;
    layer.lineCap = kCALineCapRound;
    layer.lineJoin = kCALineJoinRound;
    layer.strokeColor = [UIColor redColor].CGColor;
    [self.view.layer addSublayer:layer];
    
    // 创建贝塞尔路径~
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(10, 100)];
    [path addLineToPoint:CGPointMake(100, 200)];
    [path addLineToPoint:CGPointMake(200, 50)];
    [path addLineToPoint:CGPointMake(240, 150)];
    [path addLineToPoint:CGPointMake(300, 120)];
    
    // 关联layer和贝塞尔路径~
    layer.path = path.CGPath;
    
    // 创建Animation
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    animation.fromValue = @(0.0);
    animation.toValue = @(1.0);
    layer.autoreverses = NO;
    animation.duration = 2.0;
    
    // 设置layer的animation
    [layer addAnimation:animation forKey:nil];
    
    // 第一种设置动画完成,不移除结果的方法
    //    animation.fillMode = kCAFillModeForwards;
    //    animation.removedOnCompletion = NO;
    
    // 第二种
    layer.strokeEnd = 1;

 

用CAShapeLayer和UIBezierPath和CABaseAnimation制作动画折线图

标签:

原文地址:http://www.cnblogs.com/xyzaijing/p/4275891.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!