// 新建一个UIView
UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, 400)];
[self.view addSubview:backView];
// 复制层
CAReplicatorLayer *reLayer = [CAReplicatorLayer layer];
reLayer.frame = backView.bounds;
reLayer.backgroundColor = [UIColor greenColor].CGColor;
[backView.layer addSublayer:reLayer];
// 小layer
CALayer *subLayer = [[CALayer alloc] init];
subLayer.backgroundColor = [UIColor yellowColor].CGColor;
subLayer.bounds = CGRectMake(0, 0, 30, backView.frame.size.height);
subLayer.position = CGPointMake(30, 400);
subLayer.anchorPoint = CGPointMake(0.5, 1);
[reLayer addSublayer:subLayer];
// 小layer的动画
CABasicAnimation *animation = [CABasicAnimation animation];
animation.keyPath = @"transform.scale.x";
animation.toValue = @0.1;
animation.autoreverses = YES;
animation.repeatCount = MAXFLOAT;
animation.duration = 0.3;
[subLayer addAnimation:animation forKey:nil];
// 复制层的动画
reLayer.instanceCount = 10;
reLayer.instanceDelay = 0.3;
reLayer.instanceColor = [UIColor redColor].CGColor;
// 颜色偏移量 (范文 0 - 1)
reLayer.instanceGreenOffset = -0.1;
reLayer.instanceTransform = CATransform3DMakeTranslation(40, 0, 0);
}
网友评论