删除layer动画
[self.animationView.layer.mask removeFromSuperlayer];
[self.animationView.layer removeAllAnimations];
//上效果
下代码
渐变消失.gif
CABasicAnimation *animation = [CABasicAnimation animation];
animation.delegate = self;
[animation setDuration:2.0];
animation.keyPath = @"opacity";
animation.toValue = @(0);
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
[self.animationView.layer addAnimation:animation forKey:nil];
渐变放大消失.gif
CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
groupAnimation.delegate = self;
[groupAnimation setDuration:2.0];
CABasicAnimation *fadeAnimation = [CABasicAnimation animation];
fadeAnimation.keyPath = @"opacity";
fadeAnimation.toValue = @(0);
CABasicAnimation *zoomInAnimation = [CABasicAnimation animation];
zoomInAnimation.keyPath = @"transform.scale";
zoomInAnimation.toValue = @(2.0);
groupAnimation.animations = @[fadeAnimation,zoomInAnimation];
groupAnimation.removedOnCompletion = NO;
groupAnimation.fillMode = kCAFillModeForwards;
[self.animationView.layer addAnimation:groupAnimation forKey:nil];
点圆放大消失.gif
CGSize screenSize = [UIScreen mainScreen].bounds.size;
CAShapeLayer *maskLayer = [CAShapeLayer layer];
self.animationView.layer.mask = maskLayer;
CABasicAnimation *maskLayerAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
[maskLayerAnimation setDuration:2.0];
maskLayerAnimation.delegate = self;
UIBezierPath *beginPath = [UIBezierPath bezierPathWithRect:self.view.bounds];
UIBezierPath *beginCirclePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:1 startAngle:0 endAngle:2 * M_PI clockwise:NO];
[beginPath appendPath:beginCirclePath];
maskLayerAnimation.fromValue = (__bridge id)(beginPath.CGPath);
UIBezierPath *endPath = [UIBezierPath bezierPathWithRect:self.view.bounds];
UIBezierPath *endCirclePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:hypot(screenSize.height, screenSize.width)/2 startAngle:0 endAngle:2 * M_PI clockwise:NO];
[endPath appendPath:endCirclePath];
maskLayerAnimation.toValue = (__bridge id)((endPath.CGPath));
maskLayerAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
maskLayerAnimation.removedOnCompletion = NO;
maskLayerAnimation.fillMode = kCAFillModeForwards;
[maskLayer addAnimation:maskLayerAnimation forKey:nil];
小圆 画圆放大消失.gif
CAShapeLayer *maskLayer = [CAShapeLayer layer];
self.animationView.layer.mask = maskLayer;
CGSize screenSize = [UIScreen mainScreen].bounds.size;
CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"path"];
[keyFrameAnimation setDuration:2.0];
keyFrameAnimation.delegate = self;
UIBezierPath *pathOne = [UIBezierPath bezierPathWithRect:self.view.bounds];
UIBezierPath *pathOneCircle = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:1.0 startAngle:0 endAngle:2 * M_PI clockwise:NO];
[pathOne appendPath:pathOneCircle];
UIBezierPath *pathTwo = [UIBezierPath bezierPathWithRect:self.view.bounds];
UIBezierPath *pathTwoCircle = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:100 startAngle:0 endAngle:2 * M_PI clockwise:NO];
[pathTwo appendPath:pathTwoCircle];
UIBezierPath *pathThree = [UIBezierPath bezierPathWithRect:self.view.bounds];
UIBezierPath *pathThreeCircle = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:50 startAngle:0 endAngle:2 * M_PI clockwise:NO];
[pathThree appendPath:pathThreeCircle];
UIBezierPath *pathFour = [UIBezierPath bezierPathWithRect:self.view.bounds];
UIBezierPath *pathFourCircle = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:hypot(screenSize.height, screenSize.width)/2 startAngle:0 endAngle:2 * M_PI clockwise:NO];
[pathFour appendPath:pathFourCircle];
keyFrameAnimation.values = @[(__bridge id)(pathOne.CGPath),(__bridge id)(pathTwo.CGPath),(__bridge id)(pathThree.CGPath),(__bridge id)(pathFour.CGPath)];
// keyFrameAnimation.keyTimes = @[@(0),@(0.3),@(0.6),@(1)];
keyFrameAnimation.removedOnCompletion = NO;
keyFrameAnimation.fillMode = kCAFillModeForwards;
[maskLayer addAnimation:keyFrameAnimation forKey:nil];
缩小变成小圆 消失.gif
CAShapeLayer *maskLayer = [CAShapeLayer layer];
self.animationView.layer.mask = maskLayer;
CGSize screenSize = [UIScreen mainScreen].bounds.size;
CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"path"];
[keyFrameAnimation setDuration:2.0];
keyFrameAnimation.delegate = self;
UIBezierPath *pathOne = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:hypot(screenSize.height, screenSize.width)/2 startAngle:0 endAngle:2 * M_PI clockwise:NO];
UIBezierPath *pathTwo = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:screenSize.width/2*0.5 startAngle:0 endAngle:2 * M_PI clockwise:NO];
UIBezierPath *pathThree = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:screenSize.width/2*0.7 startAngle:0 endAngle:2 * M_PI clockwise:NO];
UIBezierPath *pathFour = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:1 startAngle:0 endAngle:2 * M_PI clockwise:NO];
keyFrameAnimation.values = @[(__bridge id)(pathOne.CGPath),(__bridge id)(pathTwo.CGPath),(__bridge id)(pathThree.CGPath),(__bridge id)(pathFour.CGPath)];
keyFrameAnimation.keyTimes = @[@(0),@(0.5),@(0.9),@(1)];
keyFrameAnimation.removedOnCompletion = NO;
keyFrameAnimation.fillMode = kCAFillModeForwards;
[maskLayer addAnimation:keyFrameAnimation forKey:nil];
圆缩小消失.gif
CAShapeLayer *maskLayer = [CAShapeLayer layer];
self.animationView.layer.mask = maskLayer;
CGSize screenSize = [UIScreen mainScreen].bounds.size;
CABasicAnimation *maskLayerAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
[maskLayerAnimation setDuration:2.0];
maskLayerAnimation.delegate = self;
UIBezierPath *beginPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:hypot(screenSize.height, screenSize.width)/2 startAngle:0 endAngle:2 * M_PI clockwise:NO];
UIBezierPath *endPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:1 startAngle:0 endAngle:2 * M_PI clockwise:NO];
maskLayerAnimation.fromValue = (__bridge id)(beginPath.CGPath);
maskLayerAnimation.toValue = (__bridge id)(endPath.CGPath);
maskLayerAnimation.removedOnCompletion = NO;
maskLayerAnimation.fillMode = kCAFillModeForwards;
[maskLayer addAnimation:maskLayerAnimation forKey:nil];