CoreAnimation之CAReplicatorLayer

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

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;
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容