美文网首页小知识点好东西收藏ios
iOS 雷达扩散动画,给view添加分类

iOS 雷达扩散动画,给view添加分类

作者: 雪_晟 | 来源:发表于2017-07-21 10:33 被阅读272次

动画有点抖s


gif.gif

给UIView添加一个分类

#import <UIKit/UIKit.h>

@interface UIView (RadarAnimation)

@property(nonatomic,strong)UIColor *radarColor; //扩散颜色
@property(nonatomic,assign)UIColor *radarBorderColor; //扩散边界颜色
-(void)addRadarAnimation;
@end

调用方法:

 button.radarColor = LBColor(237, 174, 130, 1);
 button.radarBorderColor = LBColor(237, 174, 130, 0.5);
  [button addRadarAnimation];

添加动画的方法,创建三个layer,只不过,开始动画的时间要错开形成这个效果:

-(void)Animation{
    NSInteger pulsingCount = 3;
    double animationDuration = 2;
    
    CALayer * animationLayer = [[CALayer alloc]init];
    
    for (int i = 0; i < pulsingCount; i++) {
        CALayer * pulsingLayer = [[CALayer alloc]init];
        pulsingLayer.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
        pulsingLayer.backgroundColor = self.radarColor.CGColor;
        pulsingLayer.borderColor = self.radarBorderColor.CGColor;


        pulsingLayer.borderWidth = 1.0;
        pulsingLayer.cornerRadius = self.frame.size.height/2;
        
        CAMediaTimingFunction * defaultCurve = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
        
        CAAnimationGroup * animationGroup = [[CAAnimationGroup alloc]init];
        animationGroup.fillMode = kCAFillModeBoth;
        animationGroup.beginTime = CACurrentMediaTime() + (double)i * animationDuration/(double)pulsingCount;
        animationGroup.duration = animationDuration;
        animationGroup.repeatCount = HUGE_VAL;
        animationGroup.timingFunction = defaultCurve;
        
        CABasicAnimation * scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        scaleAnimation.autoreverses = NO;
        scaleAnimation.fromValue = [NSNumber numberWithDouble:1];
        scaleAnimation.toValue = [NSNumber numberWithDouble:1.5];
        
        CAKeyframeAnimation * opacityAnimation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
        opacityAnimation.values = @[[NSNumber numberWithDouble:1.0],[NSNumber numberWithDouble:0.5],[NSNumber numberWithDouble:0.3],[NSNumber numberWithDouble:0.0]];
        opacityAnimation.keyTimes = @[[NSNumber numberWithDouble:0.0],[NSNumber numberWithDouble:0.25],[NSNumber numberWithDouble:0.5],[NSNumber numberWithDouble:1.0]];
        animationGroup.animations = @[scaleAnimation,opacityAnimation];
        
        [pulsingLayer addAnimation:animationGroup forKey:@"pulsing"];
        [animationLayer addSublayer:pulsingLayer];
    }
        animationLayer.zPosition = -1;//重新加载时,使动画至底层
    [self.layer addSublayer:animationLayer];

}

为了防止动画进入后台假死,需要监听通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidEnterPlayground) name:UIApplicationDidBecomeActiveNotification object:nil];

demo 地址:漫漫的demo

相关文章

  • iOS 雷达扩散动画,给view添加分类

    动画有点抖s 给UIView添加一个分类 调用方法: 添加动画的方法,创建三个layer,只不过,开始动画的时间要...

  • 约束、旋转动画和 iOS 7

    iOS7系统时,当在有约束的 view 上添加旋转动画时,记得把旋转动画添加的 view.layer 上面,不要直...

  • 第七章 Android动画深入分析—学习笔记

    View动画 View动画分类 TranslateAnimation、ScaleAnimation、RotateA...

  • 动画深入研究

    前言 分类 View动画,帧动画,自定义View动画,属性动画 View动画 平移,缩放,旋转,透明Transla...

  • Android动画开发精要

    3个分类 View 动画, 属性动画, 帧动画 View动画(android 3.0以下使用) Translate...

  • iOS核心动画 - 隐式动画

    添加layer代码: 执行layer动画: 添加view代码: 执行view动画 事务 Core Animatio...

  • Android动画分类

    动画分类 View动画、帧动画、属性动画 View动画包括:平移、旋转、缩放、透明度,View动画是一种渐近式动画...

  • 动画深入分析(艺术探索读书笔记)

    动画分类:帧动画、View动画、属性动画 View动画 只能作用在View上面的动画,我们平时常用的五个动画类都是...

  • 记:动画小总结

    总的来说,动画就是以上三个分类,下面详细解释各个分类及使用方法 一.View动画 View动画指定开始和结束的动画...

  • iOS自定义转场动画

    关于iOS的转场动画的实现: 转场动画实际上就是对View添加的转场效果,在CATransiton就已经给我们提供...

网友评论

    本文标题:iOS 雷达扩散动画,给view添加分类

    本文链接:https://www.haomeiwen.com/subject/qeiskxtx.html