
OC代碼實(shí)現(xiàn):
#import"ViewController.h"
@interfaceViewController()
@property(weak,nonatomic)IBOutletUIView*contentView;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
//復(fù)制層:復(fù)制里面的子層
CAReplicatorLayer*repL = [CAReplicatorLayerlayer];
repL.frame=_contentView.bounds;
//
instanceCount:表示復(fù)制層中有多少份子層,拷貝是instanceCount
- 1份
repL.instanceCount=4;
//設(shè)置復(fù)制子層偏移量,每個(gè)子層都會(huì)相對(duì)上一次偏移
repL.instanceTransform=CATransform3DMakeTranslation(40,0,0);
//延遲每個(gè)子層的動(dòng)畫(huà),相對(duì)于上一個(gè)子層延遲
repL.instanceDelay=0.2;
//設(shè)置子層的顏色
repL.instanceColor= [UIColorcolorWithWhite:1alpha:0.2].CGColor;
[_contentView.layeraddSublayer:repL];
//紅色的圖層
CALayer*layer = [CALayerlayer];
layer.backgroundColor= [UIColorredColor].CGColor;
//layer.frame = CGRectMake(0, 100, 30, 100);
layer.anchorPoint=CGPointMake(0,1);
layer.position=CGPointMake(0,200);
layer.bounds=CGRectMake(0,0,30,100);
//把紅色圖層添加到復(fù)制層中
[repLaddSublayer:layer];
CABasicAnimation*anim = [CABasicAnimationanimation];
anim.keyPath=@"transform.scale.y";
anim.toValue=@0;
anim.duration=0.5;
//設(shè)置動(dòng)畫(huà)反轉(zhuǎn)
anim.autoreverses=YES;
anim.repeatCount=MAXFLOAT;
[layeraddAnimation:animforKey:nil];
}