ReplicatorLayer 复制图层

 

使用文档介绍:

#import 

NS_ASSUME_NONNULL_BEGIN
CA_CLASS_AVAILABLE (10.6, 3.0, 9.0, 2.0)
@interface CAReplicatorLayer : CALayer

//指定图层重复制多少次
@property NSInteger instanceCount;

//设置为YES,图层将保持于CATransformLayer类似的性质和相同的限制
@property BOOL preservesDepth;

//复制延时,一般用在动画上
@property CFTimeInterval instanceDelay;

//3D变换
@property CATransform3D instanceTransform;

//设置多个复制图层的颜色,默认位白色
@property(nullable) CGColorRef instanceColor;

//设置每个复制图层相对上一个复制图层的红色、绿色、蓝色、透明度偏移量
@property float instanceRedOffset;
@property float instanceGreenOffset;
@property float instanceBlueOffset;
@property float instanceAlphaOffset;

@end

NS_ASSUME_NONNULL_END

 

例: 渐变动画

- (void)scaleAndOpcatityAnim{
    CAShapeLayer *sharLayer = [CAShapeLayer layer];
    sharLayer.backgroundColor = [UIColor redColor].CGColor;
    sharLayer.bounds = CGRectMake(0, 0, 10, 10);
    sharLayer.position = CGPointMake(kWidth/2, 150);
    sharLayer.cornerRadius = 5;
    
    //    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    //    scaleAnimation.toValue = @10;
    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
    scaleAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(10, 10, 1)];
    scaleAnimation.duration = 2;
    
    CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    opacityAnimation.fromValue = @1;
    opacityAnimation.toValue = @0;
    opacityAnimation.duration = 2;
    
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.animations = @[scaleAnimation,opacityAnimation];
    group.duration = 2;
    group.repeatCount = HUGE;
    
    [sharLayer addAnimation:group forKey:nil];
    
    
    CAReplicatorLayer *replayer = [CAReplicatorLayer layer];
    replayer.instanceDelay = 0.5;
    replayer.instanceCount = 3;
    [replayer addSublayer:sharLayer];
    
    [self.view.layer addSublayer:replayer];
    
    
}

 

参考:

https://www.cnblogs.com/xianfeng-zhang/p/7759919.html

https://www.jianshu.com/p/2e6facd8142f

 

转载于:https://www.cnblogs.com/daxueshan/p/11169694.html

你可能感兴趣的:(ReplicatorLayer 复制图层)