CAReplicatorLayer的作用是高效生成相似的圖層。它會(huì)復(fù)制出多個(gè)子圖層魄咕,并且在每個(gè)復(fù)制圖層上面應(yīng)用不同的變換,動(dòng)畫。
1 . 基本屬性簡介
@property NSInteger instanceCount; //需要復(fù)制圖層的個(gè)數(shù)
@property BOOL preservesDepth; //是否與CATransformLayer保持一樣的性質(zhì)磕诊,默認(rèn)是NO
@property CFTimeInterval instanceDelay; //延遲的時(shí)間 ,在每個(gè)圖層上做動(dòng)畫的時(shí)候需要用到
@property CATransform3D instanceTransform; //作用于每個(gè)圖層上面的變換
@property(nullable) CGColorRef instanceColor; // 設(shè)置多個(gè)復(fù)制圖層的顏色,默認(rèn)位白色
---------------------------------------------------
設(shè)置每個(gè)復(fù)制圖層相對(duì)上一個(gè)復(fù)制圖層的顏色偏移量
@property float instanceRedOffset;
@property float instanceGreenOffset;
@property float instanceBlueOffset;
---------------------------------------------------
@property float instanceAlphaOffset; //每個(gè)復(fù)制圖層相對(duì)上一個(gè)圖層透明度的衰減
2.使用CAReplicatorLayer簡單模擬水波紋外擴(kuò)
//做動(dòng)畫的圖層
CAShapeLayer *layer = [CAShapeLayer layer];
// layer.backgroundColor = [UIColor redColor].CGColor;
layer.frame = CGRectMake(0, 0, 20, 20);
layer.position = CGPointMake(25, 25);
layer.fillColor = [UIColor clearColor].CGColor;
layer.borderWidth = 1;
layer.borderColor = [UIColor redColor].CGColor;
layer.cornerRadius = 10;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
animation.duration = 2;
animation.repeatCount = MAXFLOAT;
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(10, 10, 1)];
CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
opacityAnimation.duration = 2;
opacityAnimation.repeatCount = MAXFLOAT;
opacityAnimation.toValue = @(0);
opacityAnimation.fromValue = @(1);
CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
group.animations = @[animation,opacityAnimation];
group.repeatCount = MAXFLOAT;
group.duration = 2;
[layer addAnimation:group forKey:@"dsd"];
//創(chuàng)建一個(gè)可復(fù)制圖層
CAReplicatorLayer *replicator = [CAReplicatorLayer layer];
replicator.frame = CGRectMake(0, 0, 50, 50);
[self.layer addSublayer:replicator];
replicator.instanceCount = 3;
replicator.instanceDelay = 0.3;
// replicator.instanceAlphaOffset = -0.3;
[replicator addSublayer:layer];
1.gif