使用CAReplicatorLayer [1]

使用CAReplicatorLayer [1]

 

说明

https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CAReplicatorLayer_class/

https://zsisme.gitbooks.io/ios-/content/chapter6/careplicatorLayer.html

http://www.ios-animations-by-emails.com/posts/2015-march

CAReplicatorLayer - The CAReplicatorLayer class creates a specified number of copies of its sublayers (the source layer), each copy potentially having geometric, temporal and color transformations applied to it.

 

效果

 

源码

//
//  ViewController.m
//  CAReplicatorLayer
//
//  Created by YouXianMing on 16/1/13.
//  Copyright © 2016年 YouXianMing. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    CAReplicatorLayer *replicatorLayer = [CAReplicatorLayer layer];
    replicatorLayer.frame              = CGRectMake(0, 0, 100, 100);
    replicatorLayer.position           = self.view.center;
    replicatorLayer.backgroundColor    = [UIColor grayColor].CGColor;
    
    replicatorLayer.instanceCount      = 3;
    replicatorLayer.instanceTransform  = CATransform3DMakeTranslation(20.0, 0.0, 0.0);
    replicatorLayer.instanceDelay      = 0.33f;
    
    [self.view.layer addSublayer:replicatorLayer];
    
    {
        CALayer *layer        = [CALayer layer];
        layer.frame           = CGRectMake(0, 0, 8, 40);
        layer.backgroundColor = [UIColor redColor].CGColor;
        [replicatorLayer addSublayer:layer];
        
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position.y"];
        animation.toValue           = @(layer.position.y - 25.f);
        animation.duration          = 0.5f;
        animation.autoreverses      = true;
        animation.repeatCount       = CGFLOAT_MAX;
        [layer addAnimation:animation forKey:nil];
    }
}

@end

 

细节

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值