CABasicAnimation 划线动画

CGFloat animateDuration = 2;
    
    UIBezierPath *bezierPath = [[UIBezierPath alloc] init];
    CGPoint centerFromP = noAnimateView.center;
    [bezierPath moveToPoint:centerFromP];
    CGPoint centerEndP = endView.center;
    [bezierPath addLineToPoint:centerEndP];
    
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.lineWidth = 5;
    layer.strokeColor = [UIColor blackColor].CGColor;
    layer.fillColor = [UIColor clearColor].CGColor;
    layer.path = bezierPath.CGPath;
    layer.lineCap = kCALineCapRound;
//    [layer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:15], [NSNumber numberWithInt:10],nil]];
    
    //create the keyframe animation
    CABasicAnimation *animation = [CABasicAnimation animation];
    animation.keyPath = @"strokeEnd";
    animation.fromValue = [NSNumber numberWithInteger:0];
    animation.toValue = [NSNumber numberWithInteger:1];
    animation.duration = animateDuration;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    [layer addAnimation:animation forKey:nil];

 

posted on 2018-11-14 16:30  土匪7  阅读(142)  评论(0)    收藏  举报