1.首先在storyboard上放一個(gè)lightView。
2.控制器里代碼實(shí)現(xiàn)撒遣。
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *lightView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// CAReplicatorLayer復(fù)制圖層韧骗,可以把圖層里面所有子層復(fù)制
// 創(chuàng)建復(fù)制圖層
CAReplicatorLayer *repL = [CAReplicatorLayer layer];
repL.frame = _lightView.bounds;
[_lightView.layer addSublayer:repL];
CALayer *layer = [CALayer layer];
layer.anchorPoint = CGPointMake(0.5, 1);
layer.position = CGPointMake(15, _lightView.bounds.size.height);
layer.bounds = CGRectMake(0, 0, 30, 150);
layer.backgroundColor = [UIColor whiteColor].CGColor;
[repL addSublayer:layer];
CABasicAnimation *anim = [CABasicAnimation animation];
anim.keyPath = @"transform.scale.y";
anim.toValue = @0.1;
anim.duration = 0.5;
anim.repeatCount = MAXFLOAT;
// 設(shè)置動(dòng)畫反轉(zhuǎn)
anim.autoreverses = YES;
[layer addAnimation:anim forKey:nil];
// 復(fù)制層中子層總數(shù)
// instanceCount:表示復(fù)制層里面有多少個(gè)子層竟宋,包括原始層
repL.instanceCount = 3;
// 設(shè)置復(fù)制子層偏移量凳兵,不包括原始層,相對(duì)于原始層x偏移
repL.instanceTransform = CATransform3DMakeTranslation(45, 0, 0);
// 設(shè)置復(fù)制層動(dòng)畫延遲時(shí)間
repL.instanceDelay = 0.1;
// 如果設(shè)置了原始層背景色履腋,就不需要設(shè)置這個(gè)屬性
repL.instanceColor = [UIColor greenColor].CGColor;
repL.instanceGreenOffset = -0.3;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end