CoreAnimation之CAReplicatorLayer

CAReplicatorLayer 一般用来复制层或者反射。

CoreAnimation之CAReplicatorLayer_第1张图片
3.gif
#import "ViewController.h"

@interface ViewController ()
@property(nonatomic,strong)UIView *containView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    

    self.containView =[[UIView alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2 -100, self.view.frame.size.height/2 - 100, 200, 200)];
    self.containView.backgroundColor =[UIColor redColor];
    [self.view addSubview:self.containView];
    

    CAReplicatorLayer *replayer =[CAReplicatorLayer layer];
    replayer.frame = self.containView.bounds;
    [self.containView.layer addSublayer:replayer];
    CALayer *layer = [CALayer layer];
    

    layer.frame = CGRectMake(0, replayer.bounds.size.height -150, 10, 150);

    layer.backgroundColor = [UIColor whiteColor].CGColor;
    

    
    [replayer addSublayer:layer];
    
    CABasicAnimation *anim = [CABasicAnimation animation];
    
    anim.keyPath = @"transform.scale.y";
    
    anim.toValue = @0.1;
    
    anim.duration = 0.5;
    
    anim.repeatCount = MAXFLOAT;
    
    // 设置动画反转
    anim.autoreverses = YES;
    
    
    [layer addAnimation:anim forKey:nil];
    
    
//     复制层中子层总数
//     instanceCount:表示复制层里面有多少个子层,包括原始层
    replayer.instanceCount = 5;
    
    // 设置复制子层偏移量,不包括原始层,相对于原始层x偏移
//    replayer.instanceTransform = CATransform3DIdentity;

   
    CATransform3D tranform = CATransform3DIdentity;
    tranform = CATransform3DMakeTranslation(45, 0, 0);

    

    replayer.instanceTransform =tranform;
    
    // 设置复制层动画延迟时间
    replayer.instanceDelay = 0.1;
    
    // 如果设置了原始层背景色,就不需要设置这个属性
    replayer.instanceColor = [UIColor greenColor].CGColor;
    
    replayer.instanceGreenOffset = -0.3;
}

你可能感兴趣的:(CoreAnimation之CAReplicatorLayer)