layer动画放大缩小

删除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];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在iOS实际开发中常用的动画无非是以下四种:UIView动画,核心动画,帧动画,自定义转场动画。 1.UIView...
    请叫我周小帅阅读 8,359评论 1 23
  • 显式动画 显式动画,它能够对一些属性做指定的自定义动画,或者创建非线性动画,比如沿着任意一条曲线移动。 属性动画 ...
    清风沐沐阅读 6,065评论 1 5
  • 继续继续... Core Animation使得我们可以很轻松的为app的layer添加复杂的动画. 包括改变la...
    鱼与愚七阅读 6,187评论 0 1
  • 如果想让事情变得顺利,只有靠自己--夏尔·纪尧姆 上一章介绍了隐式动画的概念。隐式动画是在iOS平台创建动态用户界...
    夜空下最亮的亮点阅读 6,025评论 0 1
  • 转载:http://www.jianshu.com/p/32fcadd12108 每个UIView有一个伙伴称为l...
    F麦子阅读 11,463评论 0 13