CAReplicatorLayer的使用示例

音量振动条

这里写图片描述

    CAReplicatorLayer *repL = [CAReplicatorLayer layer];
    [_lightView.layer addSublayer:repL];

    CALayer *layer = [CALayer layer];
    layer.anchorPoint = CGPointMake(0.5, 1);
    layer.position = CGPointMake(15, _lightView.frame.size.height);
    layer.bounds = CGRectMake(0, 0, 30, 150);
    layer.backgroundColor = [UIColor whiteColor].CGColor;
    [repL addSublayer:layer];

    CABasicAnimation *anim = [CABasicAnimation animation];
    anim.keyPath = @"transform.scale.y";
    anim.toValue = @0.1;
    anim.duration = 0.5;
    anim.repeatCount = MAXFLOAT;
    //设置动画反转
    anim.autoreverses = YES;
    [layer addAnimation:anim forKey:nil];

    //instanceCount,表示复制层里有多少个子层,包括原始层
    repL.instanceCount = 5;
    //设置复制子层偏移量,不包括原始层,相对于原始层x偏移
    repL.instanceTransform = CATransform3DMakeTranslation(45, 0, 0);
    //设置复制层动画延迟时间
    repL.instanceDelay = 0.1;
    repL.instanceColor = [UIColor greenColor].CGColor;
    repL.instanceGreenOffset = -0.2;

活动指示器

这里写图片描述

    CAReplicatorLayer *repL = [CAReplicatorLayer layer];

    repL.frame = _lightView.bounds;

    [_lightView.layer addSublayer:repL];
    CALayer *layer = [CALayer layer];

    layer.transform = CATransform3DMakeScale(0, 0, 0);

    layer.position = CGPointMake(_lightView.bounds.size.width / 2, 20);
    layer.bounds = CGRectMake(0, 0, 10, 10);
    layer.backgroundColor = [UIColor greenColor].CGColor;
    [repL addSublayer:layer];
    // 设置缩放动画
    CABasicAnimation *anim = [CABasicAnimation animation];
    anim.keyPath = @"transform.scale";
    anim.fromValue = @1;
    anim.toValue = @0;
    anim.repeatCount = MAXFLOAT;
    CGFloat duration = 1;
    anim.duration = duration;
    [layer addAnimation:anim forKey:nil];
    int count = 20;

    CGFloat angle = M_PI * 2 / count;

    // 设置子层总数
    repL.instanceCount = count;

    repL.instanceTransform = CATransform3DMakeRotation(angle, 0, 0, 1);

    repL.instanceDelay = duration / count;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值