2019獨角獸企業重金招聘Python工程師標準>>>
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;
例子:
// 背景 layerCAReplicatorLayer * 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];// 單個layerCALayer *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;
效果:
?
?
?
?