CAReplicatorLayer
- (void)configReplicatorLayer
{
NSInteger count = CGRectGetWidth(self.frame) /(2 * self.layerMargin + layerWidth) ;
CAReplicatorLayer * replicatorLayer = (CAReplicatorLayer *)self.layer;
replicatorLayer.instanceCount = count;
replicatorLayer.instanceColor = self.layerColor.CGColor;
replicatorLayer.instanceTransform = CATransform3DMakeTranslation(self.layerMargin * 2 + layerWidth, 0, 0);
replicatorLayer.preservesDepth = YES;
replicatorLayer.instanceDelay = self.instanceDelay;
replicatorLayer.instanceGreenOffset = 0.1;
}
- (void) initSubLayers
{
self.animationLayer.frame = CGRectMake(self.layerMargin, 0, layerWidth, CGRectGetHeight(self.frame));
self.animationLayer.anchorPoint = CGPointMake(0.5, 1);
self.animationLayer.position = CGPointMake(layerWidth/2.0, CGRectGetHeight(self.frame));
self.animationLayer.backgroundColor = [UIColor greenColor].CGColor;
[self.layer addSublayer:self.animationLayer];
self.animationLayer.transform = CATransform3DScale(self.animationLayer.transform, 1, 0.2, 1);
}
- (void)startAnimation
{
if (_isAnimation){
return ;
}
CABasicAnimation * basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
basicAnimation.toValue = @(1.0);
basicAnimation.fromValue = @(0);
basicAnimation.repeatCount = MAXFLOAT;
basicAnimation.duration = self.duration;
basicAnimation.autoreverses = YES;
basicAnimation.removedOnCompletion = NO;
basicAnimation.fillMode = kCAFillModeForwards;
[self.animationLayer addAnimation:basicAnimation forKey:@"scale"];
_isAnimation = YES;
}
Last updated