https://github.com/YouXianMing

使用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

 

细节

 

posted @ 2016-01-13 22:37  YouXianMing  阅读(647)  评论(0编辑  收藏  举报