Core Animation实例2-活动指示器(CAReplicatorLayer复制层)

demo

这里写图片描述
可以利用CAReplicatorLayer复制层给View添加一直活动状态的动画,并且可以设置复制时间与动画时间的比值,设定显示效果,比如说上图:复制时间是动画时间的三倍,显示三个动画效果
直接上代码

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    // 创建复制层
    CAReplicatorLayer *repL = [CAReplicatorLayer layer];

    repL.frame = _redView.bounds;

    CGFloat count = 30;

    CGFloat angle = M_PI * 2 / count;

    repL.instanceCount = count;

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

    // 设置复制延迟动画时间 = 动画时间 / 总的个数
    repL.instanceDelay = 3 / count;

    [_redView.layer addSublayer:repL];

    CGFloat w = 15;

    // 绿色
    CALayer *greenLayer = [CALayer layer];


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

    greenLayer.position = CGPointMake(_redView.bounds.size.width * 0.5, w);
    greenLayer.bounds = CGRectMake(0, 0, w, w);

    greenLayer.backgroundColor = [UIColor greenColor].CGColor;

    [repL addSublayer:greenLayer];


    CABasicAnimation *anim = [CABasicAnimation animation];

    anim.keyPath = @"transform.scale";

    anim.fromValue = @1;

    anim.toValue = @0;

    anim.repeatCount = MAXFLOAT;

    anim.duration = 1;

    [greenLayer addAnimation:anim forKey:nil];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值