动画,震动条

作者: LST程序员 | 来源:发表于2016-08-20 11:20 被阅读0次
    2016-08-20 11_12_25.gif
    // 新建一个UIView
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, 400)];
    [self.view addSubview:backView];
    // 复制层
    CAReplicatorLayer *reLayer = [CAReplicatorLayer layer];
    reLayer.frame = backView.bounds;
    reLayer.backgroundColor = [UIColor greenColor].CGColor;
    [backView.layer addSublayer:reLayer];
    
    // 小layer
    CALayer *subLayer = [[CALayer alloc] init];
    subLayer.backgroundColor = [UIColor yellowColor].CGColor;
    subLayer.bounds = CGRectMake(0, 0, 30, backView.frame.size.height);
    subLayer.position = CGPointMake(30, 400);
    subLayer.anchorPoint = CGPointMake(0.5, 1);
    [reLayer addSublayer:subLayer];
    // 小layer的动画
    
    CABasicAnimation *animation = [CABasicAnimation animation];
    animation.keyPath = @"transform.scale.x";
    animation.toValue = @0.1;
    
    animation.autoreverses = YES;
    animation.repeatCount = MAXFLOAT;
    animation.duration = 0.3;
    [subLayer addAnimation:animation forKey:nil];
    // 复制层的动画
    reLayer.instanceCount = 10;
    reLayer.instanceDelay = 0.3;
    reLayer.instanceColor = [UIColor redColor].CGColor;
    // 颜色偏移量 (范文 0 - 1)
    reLayer.instanceGreenOffset = -0.1;
    reLayer.instanceTransform = CATransform3DMakeTranslation(40, 0, 0);
    

    }

    相关文章

      网友评论

        本文标题: 动画,震动条

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