以前看高級(jí)動(dòng)畫的時(shí)候,知道CAReplicatorLayer 重復(fù)圖層,沒怎么去用,今天看別人博客看到這個(gè),感覺挺適合做一些動(dòng)畫效果,于是自己嘗試一下,做了個(gè)簡(jiǎn)單動(dòng)畫。
- (void)viewDidLoad
{
[super viewDidLoad];
CAReplicatorLayer *replicatiorLayer = [CAReplicatorLayer layer];
replicatiorLayer.frame = CGRectMake(100, 64, 350 , 350);
replicatiorLayer.position = CGPointMake(self.view.bounds.size.width / 2, self.view.bounds.size.height / 2);
replicatiorLayer.instanceCount= 16;
replicatiorLayer.instanceTransform = CATransform3DMakeRotation(2 * M_PI / 16, 0, 0, 1);
replicatiorLayer.instanceBlueOffset = -0.1;
replicatiorLayer.instanceRedOffset = -0.1;
replicatiorLayer.instanceDelay = 1.0 / 16; ;
CALayer *layer = [CALayer layer];
layer.anchorPoint = CGPointMake(0.0, 0.0);
layer.frame = CGRectMake(80, 150, 30, 30);
layer.cornerRadius = 15;
layer.backgroundColor = [UIColor colorWithRed:200/ 255.0 green:200/ 255.0 blue:244/ 255.0 alpha:1].CGColor;
[replicatiorLayer addSublayer:layer];
[self.view.layer addSublayer:replicatiorLayer];
CABasicAnimation *baseAnimation = [CABasicAnimation animation];
baseAnimation.keyPath = @"transform.scale";
baseAnimation.fromValue = @(1.0);
baseAnimation.toValue = @(0.1);
baseAnimation.repeatCount = MAXFLOAT;
baseAnimation.duration = 1.0;
[layer addAnimation:baseAnimation forKey:@"baseAnimation"];
}
188.gif