zoukankan      html  css  js  c++  java
  • 用CAShapeLayer和UIBezierPath和CABaseAnimation制作动画折线图

     // 创建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;
  • 相关阅读:
    表详细操作
    库相关操作
    数据库一
    协程
    多线程2
    .Net鼠标随动窗口
    .Net操作音频
    .Net操作注册表--un
    .Net操作.exe文件
    .Net连接数据库(AOD.Net)
  • 原文地址:https://www.cnblogs.com/xyzaijing/p/4275891.html
Copyright © 2011-2022 走看看