向外扩散的圆形动画
-(void)addanimationwithView:(UIView *)circleView{
NSInteger pulsingCount = 5;
double animationDuration = 5;
CALayer *animationLayer = [CALayer layer];
for (int i = 0; i < pulsingCount; i++) {
CALayer * pulsingLayer = [CALayer layer];//
pulsingLayer.frame = CGRectMake(0, 0, circleView.frame.size.width, circleView.frame.size.height);
pulsingLayer.frame = CGRectMake(0, 0, YC_directionX(300), YC_directionX(300));//
pulsingLayer.frame = circleView.bounds;//
pulsingLayer.borderColor = NavColor.CGColor; pulsingLayer.borderColor = [UIColor colorWithHexString:@"#CFEECF"].CGColor;
pulsingLayer.borderWidth = 15;//
pulsingLayer.cornerRadius = circleView.frame.size.width / 2;
pulsingLayer.cornerRadius = YC_directionX(150);
CAMediaTimingFunction * defaultCurve = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
CAAnimationGroup * animationGroup = [CAAnimationGroup animation];
animationGroup.fillMode = kCAFillModeBackwards;
animationGroup.beginTime = CACurrentMediaTime() + (double)i * animationDuration / (double)pulsingCount;
animationGroup.duration = animationDuration;
animationGroup.repeatCount = HUGE;
animationGroup.timingFunction = defaultCurve;
animationGroup.removedOnCompletion = false;
CABasicAnimation * scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.fromValue = @1.0;
scaleAnimation.toValue = @2.2;
CAKeyframeAnimation * opacityAnimation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
opacityAnimation.values = @[@1, @0.9, @0.8, @0.7, @0.6, @0.5, @0.4, @0.3, @0.2, @0.1, @0];
opacityAnimation.keyTimes = @[@0, @0.1, @0.2, @0.3, @0.4, @0.5, @0.6, @0.7, @0.8, @0.9, @1];
animationGroup.animations = @[scaleAnimation, opacityAnimation];
[pulsingLayer addAnimation:animationGroup forKey:@"plulsing"];
[animationLayer addSublayer:pulsingLayer];
}
[circleView.layer addSublayer:animationLayer];
}