CAReplicatorLayer简单使用
- (void)viewDidLoad {
[super viewDidLoad];
[self setReplicatorLayer];
}
- (void)setReplicatorLayer{
CAReplicatorLayer *rLayer = [[CAReplicatorLayer alloc] init];![在这里插入图片描述](https://img-blog.csdnimg.cn/20190102150348885.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3QzMDM1,size_16,color_FFFFFF,t_70)
rLayer.frame = (CGRect){{0, 100}, {500, 80}};
rLayer.backgroundColor = [UIColor greenColor].CGColor;
CALayer *redLayer = [[CALayer alloc] init];
redLayer.backgroundColor = [UIColor whiteColor].CGColor;
redLayer.frame = (CGRect){{0, 10}, {60, 60}};
NSInteger instanceCount = 5;
rLayer.instanceCount = instanceCount;
// 70 为间隔 + layer的width
rLayer.instanceTransform = CATransform3DMakeTranslation(70, 0, 0);
// 控制颜色变化快慢
CGFloat offsetStep = -1.0 / instanceCount;
rLayer.instanceBlueOffset = offsetStep;
rLayer.instanceGreenOffset = offsetStep;
[rLayer addSublayer:redLayer];
// 嵌套layer
CAReplicatorLayer *outerReplicatorLayer = [[CAReplicatorLayer alloc] init];
[outerReplicatorLayer addSublayer:rLayer];
outerReplicatorLayer.instanceCount = instanceCount;
outerReplicatorLayer.instanceTransform = CATransform3DMakeTranslation(0, 70, 0);
outerReplicatorLayer.instanceRedOffset = offsetStep;
[self.view.layer addSublayer:outerReplicatorLayer];
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/23b5626e60a0e1b7a4e958c02eaf8fa5.png)