CAReplicatorLayer 是本質(zhì)上是一個繼承于 CALayer 的,
它的作用是可以生成很多相似的圖層,這些圖層都是他的子圖層
常用的屬性有:
instanceCount: 拷貝圖層的次數(shù),
preservesDepth: 如果設(shè)置為 YES,圖層將保持和 CATransformLayer 相同的性質(zhì)和限制
instanceDelay: 后一個子圖層和前一個子圖層的時間間隔
instanceTransform:設(shè)置兩個子圖層之間的 偏移量
instanceColor: 設(shè)置層的顏色,前提是要設(shè)置子層的背景顏色,否則不會生效
instanceRedOffset、instanceGreenOffset艰垂、instanceBlueOffset:顏色的漸變速警,相對
于前一個層的漸變(取值-1~+1).RGB有三種顏色沛鸵,所以這里也是紅綠藍三種。
instanceAlphaOffset:相對于前一個層透明圖的漸變冕臭。
下面上實例:
self.view.backgroundColor = [UIColor whiteColor];
CALayer *layer = [[CALayer alloc] init];
layer.frame = CGRectMake(30, 200, 20, 80);
layer.backgroundColor = [UIColor redColor].CGColor;
[layer addAnimation:[self scaleAnimation] forKey:@"transform"];
CAReplicatorLayer *replayLayer = [[CAReplicatorLayer alloc] init];
replayLayer.instanceCount = 5;
replayLayer.instanceDelay = 0.3;
replayLayer.instanceTransform = CATransform3DMakeTranslation(50, 0, 0);
[replayLayer addSublayer:layer];
[self.view.layer addSublayer:replayLayer];
}
- (CAAnimation *)scaleAnimation
{
CABasicAnimation *basic = [[CABasicAnimation alloc] init];
basic.toValue = @0.3;
basic.duration = 1;
basic.removedOnCompletion = NO;
basic.fillMode = kCAFillModeForwards;
basic.keyPath = @"transform.scale.y";
// the object plays backwards after playing forwards
basic.autoreverses = YES;
basic.repeatCount = MAXFLOAT;
return basic;
}
效果圖為: