CAReplicatorLayer是一个layer容器,会对其中的subLayer进行一些差异处理(它的子layer都可以拷贝)
属性:
//拷贝的次数
@property NSInteger instanceCount;
//是否开启景深效果
@property BOOL preservesDepth;
//当CAReplicatorLayer的子Layer层进行动画的时候,拷贝的副本执行动画的延时
@property CFTimeInterval instanceDelay;
//拷贝副本的3D变换
@property CATransform3D instanceTransform;
//拷贝副本的颜色变换
@property(nullable) CGColorRef instanceColor;
//每个拷贝副本的颜色偏移参数
@property float instanceRedOffset;
@property float instanceGreenOffset;
@property float instanceBlueOffset;
//每个拷贝副本的透明度偏移参数
@property float instanceAlphaOffset;
例子:
// 背景 layer
CAReplicatorLayer * replicatorLayer = [CAReplicatorLayer layer];
replicatorLayer.frame = CGRectMake(80, 100, 200, 200);
replicatorLayer.cornerRadius = 10;
replicatorLayer.backgroundColor = [UIColor colorWithWhite:0 alpha:0.75].CGColor;
[self.view.layer addSublayer:replicatorLayer];
// 单个layer
CALayer *layer = [CALayer layer];
layer.frame = CGRectMake(80, 20, 20, 20);
layer.backgroundColor = [UIColor redColor].CGColor;
[replicatorLayer addSublayer:layer];
CABasicAnimation *animation = [CABasicAnimation animation];
animation.keyPath = @"transform.scale";
animation.fromValue = @(1);
animation.toValue = @(0.1);
animation.duration = 1.5;
animation.repeatCount = MAXFLOAT;
[layer addAnimation:animation forKey:nil];
// 设置拷贝份数
int number = 15;
CGFloat angle = 2 * M_PI / 15;
replicatorLayer.instanceCount = number;
// 拷贝副本的3D变换
replicatorLayer.instanceTransform = CATransform3DMakeRotation(angle, 0, 0, 1);
// 设置延时
replicatorLayer.instanceDelay = 1.5 / 15;
效果: