OC代碼實現:
#import"ViewController.h"
@interfaceViewController()
@property(weak,nonatomic)IBOutletUIView*contentView;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
//復制層:復制里面的子層
CAReplicatorLayer*repL = [CAReplicatorLayerlayer];
repL.frame=_contentView.bounds;
//
instanceCount:表示復制層中有多少份子層,拷貝是instanceCount
- 1份
repL.instanceCount=4;
//設置復制子層偏移量,每個子層都會相對上一次偏移
repL.instanceTransform=CATransform3DMakeTranslation(40,0,0);
//延遲每個子層的動畫,相對于上一個子層延遲
repL.instanceDelay=0.2;
//設置子層的顏色
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);
//把紅色圖層添加到復制層中
[repLaddSublayer:layer];
CABasicAnimation*anim = [CABasicAnimationanimation];
anim.keyPath=@"transform.scale.y";
anim.toValue=@0;
anim.duration=0.5;
//設置動畫反轉
anim.autoreverses=YES;
anim.repeatCount=MAXFLOAT;
[layeraddAnimation:animforKey:nil];
}