美文网首页
CAShapLayer的应用和coreAnimation

CAShapLayer的应用和coreAnimation

作者: 狒狒James_Leo | 来源:发表于2016-09-03 20:38 被阅读0次

    画勾:
    CAShapLayer给定一个路径它就能跟着你的路径画出一个你想要的图形

    CAAnimation——速度控制函数
    
    速度控制函数(CAMediaTimingFunction) 
    
    kCAMediaTimingFunctionLinear(线性):匀速,给你一个相对静态的感觉
    
    kCAMediaTimingFunctionEaseIn(渐进):动画缓慢进入,然后加速离开
    
    kCAMediaTimingFunctionEaseOut(渐出):动画全速进入,然后减速的到达目的地
    
    kCAMediaTimingFunctionEaseInEaseOut(渐进渐出):动画缓慢的进入,中间加速,然后减速的到达目的地。这个是默认的动画行为。
    
     
    
    设置动画的执行节奏
    
    anim.timingFunction= [CAMediaTimingFunction
    functionWithName:kCAMediaTimingFunctionLinear];
    - (void)drawPic:(CGRect)rect context:(CGContextRef)context {
        
        
        
        _shap = [CAShapeLayer layer];
        CGPoint point[3] = {{150,200},{200,250},{300,150}};
        
        CGMutablePathRef mu = CGPathCreateMutable();
        
        CGPathAddLines(mu, nil, point, 3);
        
        _shap.path  = mu;
    
        _shap.strokeStart = 0;
        _shap.strokeEnd = 1;
        _shap.fillColor = [UIColor clearColor].CGColor;
        _shap.strokeColor = [UIColor redColor].CGColor;
        _shap.lineWidth = 13;
        [self.layer addSublayer:_shap];
        
        
        //动画
        CABasicAnimation *base = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        base.fromValue =  @(0);
        base.toValue = @(1);
        base.duration = 2;
        base.repeatCount = CGFLOAT_MAX;
        
    //    base.fillMode = @"forwards";
    //    base.removedOnCompletion = NO;
        
        [_shap addAnimation:base forKey:@"d"];
        
        CGPathRelease(mu);
        
    }
    
    

    相关文章

      网友评论

          本文标题:CAShapLayer的应用和coreAnimation

          本文链接:https://www.haomeiwen.com/subject/mvxlettx.html