iOS电流充电流动 动画

2018-04-04  本文已影响172人  XLsn0w

UIView *layerView = [[UIView alloc] initWithFrame:CGRectMake(20,150,[UIScreen mainScreen].bounds.size.width-40,200)];

[self.viewaddSubview:layerView];

    //绘制心电图背景

    CAShapeLayer*lineShapeLayer = [CAShapeLayerlayer];

    lineShapeLayer.frame=CGRectMake(0,0,600,300);

    lineShapeLayer.path= [selfbezierPath].CGPath;

    lineShapeLayer.fillColor= [UIColorclearColor].CGColor;

    lineShapeLayer.strokeColor= [UIColorwhiteColor].CGColor;

    lineShapeLayer.lineWidth=2;

    lineShapeLayer.opacity=0.5;

    lineShapeLayer.position= layerView.center;

    lineShapeLayer.transform=CATransform3DMakeScale(0.9,0.9,1.0f);

    [layerView.layeraddSublayer:lineShapeLayer];

//流动的layer

    CAShapeLayer*scrollShapeLayer = [CAShapeLayerlayer];

    scrollShapeLayer.frame=CGRectMake(0,0,600,300);

    scrollShapeLayer.position= layerView.center;

    scrollShapeLayer.path= [selfbezierPath].CGPath;

    scrollShapeLayer.strokeEnd=0.f;

    scrollShapeLayer.lineWidth=3;

    scrollShapeLayer.fillColor= [UIColorclearColor].CGColor;

    scrollShapeLayer.strokeColor= [UIColorgreenColor].CGColor;

    scrollShapeLayer.shadowColor= [UIColorgreenColor].CGColor;

    scrollShapeLayer.shadowRadius=4;

    scrollShapeLayer.shadowOpacity=1;

    scrollShapeLayer.lineCap=kCALineCapRound;

    scrollShapeLayer.transform=CATransform3DMakeScale(0.9,0.9,1.0f);

    [layerView.layeraddSublayer:scrollShapeLayer];

    CABasicAnimation*strokeStartAnimation = [CABasicAnimationanimationWithKeyPath:@"strokeStart"];

    strokeStartAnimation.fromValue=@0;

    strokeStartAnimation.toValue=@(0.95);

    CABasicAnimation *strokeEndAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];

    strokeEndAnimation.fromValue=@(0.05);

    strokeEndAnimation.toValue=@(1);

    CAAnimationGroup *group = [CAAnimationGroup animation];

    group.duration=8.f;

    group.repeatCount=MAXFLOAT;

    group.autoreverses=NO;///来回循环

    group.animations=@[strokeStartAnimation, strokeEndAnimation];

    [scrollShapeLayeraddAnimation:groupforKey:nil];

上一篇 下一篇

猜你喜欢

热点阅读