雷达动画ios_ios 雷达广播动画 - CSDN
精华内容
参与话题
  • 简单模仿咻一咻动画效果
  • iOS开发雷达动画效果实现

    千次阅读 2015-07-11 13:57:37
    感觉比较棒的一款雷达效果实现。具体先看效果图 直接上代码: @interface CCRadarView() @property (nonatomic,weak)CALayer * animationLayer; @end @implementation CCRadarView -(instancetype)...

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">具体先看效果图</span>


    直接上代码:


    @interface CCRadarView : UIView
    
    /*当前雷达中心缩略图*/
    @property (nonatomic,strong)UIImage * thumbnailImage;
    
    -(instancetype)initWithFrame:(CGRect)frame andThumbnail:(NSString *)thumbnailUrl;
    
    
    @end
    



    @interface CCRadarView()
    
    @property (nonatomic,weak)CALayer * animationLayer;
    
    @end
    
    @implementation CCRadarView
    </pre><pre name="code" class="objc"><pre name="code" class="objc">-(instancetype)initWithFrame:(CGRect)frame andThumbnail:(NSString *)thumbnailUrl{
        self = [super initWithFrame:frame];
        if (self) {
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resume) name:UIApplicationDidBecomeActiveNotification object:nil];
            
            self.backgroundColor = [UIColor clearColor];
            self.thumbnailImage = [UIImage imageNamed:@"friends_default_portrait.png"];
        }
        return self;
    }
    


    
    

    - (void)drawRect:(CGRect)rect {
        
        [[UIColor clearColor] setFill];
        
        UIRectFill(rect);
        
        NSInteger pulsingCount = 3;//雷达上波纹的条数
        double animationDuration = 2;//一组动画持续的时间,直接决定了动画运行快慢。
        
        CALayer * animationLayer = [[CALayer alloc]init];
        self.animationLayer = animationLayer;
        
        for (int i = 0; i < pulsingCount; i++) {
            CALayer * pulsingLayer = [[CALayer alloc]init];
            pulsingLayer.frame = CGRectMake(0, 0, rect.size.width, rect.size.height);
            pulsingLayer.backgroundColor = [UIColor colorWithHexRGB:@"d2e5fb"].CGColor;//圈圈背景颜色,不设置则为透明。
            pulsingLayer.borderColor = [UIColor colorWithHexRGB:@"d2e5fb"].CGColor;
            pulsingLayer.borderWidth = 1.0;
            pulsingLayer.cornerRadius = rect.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:0.2];
            scaleAnimation.toValue = [NSNumber numberWithDouble:1.0];
            
            //雷达圆圈在n个运行阶段的透明度,n为数组长度。
            CAKeyframeAnimation * opacityAnimation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
            //雷达运行四个阶段不同的透明度。
            opacityAnimation.values = @[[NSNumber numberWithDouble:1.0],[NSNumber numberWithDouble:0.5],[NSNumber numberWithDouble:0.3],[NSNumber numberWithDouble:0.0]];
            //雷达运行的不同的四个阶段,为0.0表示刚运行,0.5表示运行了一半,1.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];
        }
        [self.layer addSublayer:self.animationLayer];
        
        //以下部分为雷达中心的用户缩略图。雷达圈圈也是从该图中心发出。
        CALayer * thumbnailLayer = [[CALayer alloc]init];
        thumbnailLayer.backgroundColor = [UIColor whiteColor].CGColor;
        CGRect thumbnailRect = CGRectMake(0, 0, 46, 46);
        thumbnailRect.origin.x = (rect.size.width - thumbnailRect.size.width)/2.0;
        thumbnailRect.origin.y = (rect.size.height - thumbnailRect.size.height)/2.0;
        thumbnailLayer.frame = thumbnailRect;
        thumbnailLayer.cornerRadius = 23.0;
        thumbnailLayer.borderWidth = 1.0;
        thumbnailLayer.masksToBounds = YES;
        thumbnailLayer.borderColor = [UIColor whiteColor].CGColor;
        UIImage * thumbnail = self.thumbnailImage;
        thumbnailLayer.contents = (id)thumbnail.CGImage;
        [self.layer addSublayer:thumbnailLayer];
        
        
    }
    <pre name="code" class="objc">// 动画因应用程序进入后台后会停止。故避免在重新激活程序时出现卡死假象。
    - (void)resume{
        
        if (self.animationLayer) {
            [self.animationLayer removeFromSuperlayer];
            [self setNeedsDisplay];
        }
    }
    
    
    -(void)dealloc{
        [[NSNotificationCenter defaultCenter]removeObserver:self];
    }


    
    
    </pre><pre name="code" class="objc">其中有个uicolor  (category)
    </pre><pre name="code" class="objc"><pre name="code" class="objc">+ (UIColor *)colorWithHexRGB:(NSString *)rbg
    {
        NSString *cString = [[rbg stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
        if (cString.length < 6) {
            return [UIColor clearColor];
        }
        
        if ([cString hasPrefix:@"0X"]) {
            cString = [cString substringFromIndex:2];
        }
        if ([cString hasPrefix:@"#"]) {
            cString = [cString substringFromIndex:1];
        }
        if (cString.length != 6) {
            return [UIColor clearColor];
        }
        
        NSRange range = NSMakeRange(0, 2);
        NSString *rString = [cString substringWithRange:range];
        
        range.location = 2;
        NSString *gString = [cString substringWithRange:range];
        
        range.location = 4;
        NSString *bString = [cString substringWithRange:range];
        
        unsigned int red = 0;
        unsigned int green= 0;
        unsigned int blue = 0;
        [[NSScanner scannerWithString:rString] scanHexInt:&red];
        [[NSScanner scannerWithString:gString] scanHexInt:&green];
        [[NSScanner scannerWithString:bString] scanHexInt:&blue];
        
        return [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:1.0];
    }
    
    @end

    
    
    原帖地址:http://blog.csdn.net/zhangao0086/article/details/38170359

    展开全文
  • ios-雷达图(Swift).zip

    2020-05-12 23:30:06
    雷达图上的点跟随手机的方向旋转
  • iOS 自定义雷达 扫描/扩散动画 View

    千次阅读 2017-03-04 12:53:07
    雷达扫描/扩散效果的View, 雷达扫描View 类似微信雷达扫描附近好友界面;雷达扩散View 类似支付宝咻一咻界面。

    
    
    前段时间 没事儿,自己自定义了 一个雷达扫描/扩散效果的View。

    扫描View 效果如下:



    扩散View 效果如下:



    自定义的代码如下:

    1. RadarView.h

    #import <UIKit/UIKit.h>
    
    typedef NS_ENUM(NSInteger, RadarViewType) {
        RadarViewTypeScan,
        RadarViewTypeDiffuse
    };
    
    @interface RadarView : UIView
    
    /** 雷达 空心圆圈的颜色 */
    @property (nonatomic, strong) UIColor * radarLineColor;
    /** 扇形开始颜色 必须由RGBA值初始化
     *  [UIColor colorWithRed: green: blue: alpha:]
     */
    @property (nonatomic, strong) UIColor * startColor;
    /** 扇形结束颜色 必须由RGBA值初始化
     *  [UIColor colorWithRed: green: blue: alpha:]
     */
    @property (nonatomic, strong) UIColor * endColor;
    
    /**
     *
     *  @param radius       半径
     *  @param angle        角度
     *  @param radarLineNum 雷达线数量
     *  @param hollowRadius 空心圆半径
     *
     *  @return 扫描 雷达 View
     */
    + (RadarView *)scanRadarViewWithRadius:(CGFloat)radius
                                     angle:(int)angle
                              radarLineNum:(int)radarLineNum
                              hollowRadius:(CGFloat)hollowRadius;
    
    
    /**
     *
     *  @param startRadius 扩散圆 起始的半径
     *  @param endRadius   扩散圆 消失的半径
     *  @param circleColor 扩散圆 的颜色
     *
     *  @return 扩散 雷达 View
     */
    + (RadarView *)diffuseRadarViewWithStartRadius:(CGFloat)startRadius
                                         endRadius:(CGFloat)endRadius
                                       circleColor:(UIColor *)circleColor;
    
    /**
     *  展示在targerView上
     *
     *  @param targerView <#targerView description#>
     */
    - (void)showTargetView:(UIView *)targerView;
    
    - (void)dismiss;
    
    /** 开始扫描动画 */
    - (void)startAnimatian;
    
    /** 停止扫描动画 */
    - (void)stopAnimation;
    
    @end
    

    2. RadarView.m

    #import "RadarView.h"
    
    #define CenterX self.bounds.size.width*0.5
    #define CenterY self.bounds.size.height*0.5
    
    #define DefaultRadarLineColor [UIColor colorWithWhite:1 alpha:0.7]
    #define DefaultStartColor [UIColor colorWithRed:1 green:1 blue:1 alpha:0.5]
    #define DefaultEndColor [UIColor colorWithRed:1 green:1 blue:1 alpha:0]
    
    #define DefaultCircleColor [UIColor colorWithWhite:1 alpha:0.5]
    
    @interface RadarView ()
    
    #pragma mark - 扫描类型的RadarView 属性
    /** 扇形半径 */
    @property (nonatomic, assign) CGFloat sectorRadius;
    /** 扇形 角度 */
    @property (nonatomic, assign) int angle;
    /** 雷达 空心圆圈的数量 */
    @property (nonatomic, assign) int radarLineNum;
    /** 中心 空心圆的半径 (一般 这里放置一个圆形的头像) */
    @property (nonatomic, assign) int hollowRadius;
    
    #pragma mark - 扩散类型的RadarView 属性
    /** 扩散动画 起始 的半径 */
    @property (nonatomic, assign) CGFloat startRadius;
    /** 扩散动画 结束 的半径 */
    @property (nonatomic, assign) CGFloat endRadius;
    /** 圆圈的颜色 */
    @property (nonatomic, strong) UIColor * circleColor;
    
    @property (nonatomic, strong) NSTimer * timer;
    
    @property (nonatomic, assign) RadarViewType radarViewType;
    
    @end
    
    @implementation RadarView
    
    + (RadarView *)scanRadarViewWithRadius:(CGFloat)radius angle:(int)angle radarLineNum:(int)radarLineNum hollowRadius:(CGFloat)hollowRadius {
        return [[self alloc] initWithRadius:radius angle:angle radarLineNum:radarLineNum hollowRadius:hollowRadius];
    }
    
    - (instancetype)initWithRadius:(CGFloat)radius
                             angle:(int)angle
                      radarLineNum:(int)radarLineNum
                      hollowRadius:(CGFloat)hollowRadius {
        if (self = [super init]) {
            self.radarViewType = RadarViewTypeScan;
            self.sectorRadius = radius;
            self.frame = CGRectMake(0, 0, radius*2, radius*2);
            self.angle = angle;
            self.radarLineNum = radarLineNum-1;
            self.hollowRadius = hollowRadius;
            self.backgroundColor = [UIColor clearColor];
        }
        return self;
    }
    
    + (RadarView *)diffuseRadarViewWithStartRadius:(CGFloat)startRadius endRadius:(CGFloat)endRadius circleColor:(UIColor *)circleColor {
        return [[self alloc] initWithStartRadius:startRadius endRadius:endRadius circleColor:circleColor];
    }
    
    - (instancetype)initWithStartRadius:(CGFloat)startRadius endRadius:(CGFloat)endRadius circleColor:(UIColor *)circleColor {
        if (self = [super init]) {
            self.radarViewType = RadarViewTypeDiffuse;
            self.frame = CGRectMake(0, 0, endRadius*2, endRadius*2);
            self.startRadius = startRadius;
            self.endRadius = endRadius;
            self.circleColor = circleColor;
            self.backgroundColor = [UIColor clearColor];
        }
        return self;
    }
    
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    - (void)drawRect:(CGRect)rect {
        // Drawing code
        if (_radarViewType == RadarViewTypeScan) {
            if (!_startColor) {
                _startColor = DefaultStartColor;
            }
            if (!_endColor) {
                _endColor = DefaultEndColor;
            }
            if (!_radarLineColor) {
                _radarLineColor = DefaultRadarLineColor;
            }
            
            // 画雷达线
            [self drawRadarLine];
            
            CGContextRef context = UIGraphicsGetCurrentContext();
            // 把要画的扇形 分开画,一次画1°,每次的颜色渐变
            for (int i = 0; i < _angle; i++) {
                UIColor * color = [self colorWithCurrentAngleProportion:i*1.0/_angle];
                [self drawSectorWithContext:context color:color startAngle:-90-i];
            }
        }
    }
    
    /** 画扇形 */
    - (void)drawSectorWithContext:(CGContextRef)context
                            color:(UIColor *)color
                       startAngle:(CGFloat)startAngle {
        //画扇形,也就画圆,只不过是设置角度的大小,形成一个扇形
        CGContextSetFillColorWithColor(context, color.CGColor);//填充颜色
        CGContextSetLineWidth(context, 0);//线的宽度
        //以self.radius为半径围绕圆心画指定角度扇形
        CGContextMoveToPoint(context, CenterX, CenterY);
        CGContextAddArc(context, CenterX, CenterY, _sectorRadius, startAngle * M_PI / 180, (startAngle-1) * M_PI / 180, 1);
        CGContextClosePath(context);
        CGContextDrawPath(context, kCGPathFillStroke); //绘制路径
    }
    
    
    /** 画雷达线 */
    - (void)drawRadarLine {
        CGFloat minRadius = (_sectorRadius-_hollowRadius)*(pow(0.618, _radarLineNum-1));
        /** 画 围着空心半径的第一个空心圆,此圆不在计数内 */
        [self drawLineWithRadius:_hollowRadius+minRadius*0.382];
        
        for (int i = 0; i < _radarLineNum; i++) {
            [self drawLineWithRadius:_hollowRadius + minRadius/pow(0.618, i)];
        }
    }
    
    /** 画空心圆 */
    - (void)drawLineWithRadius:(CGFloat)radius {
        CAShapeLayer *solidLine =  [CAShapeLayer layer];
        CGMutablePathRef solidPath =  CGPathCreateMutable();
        solidLine.lineWidth = 1.0f ;
        solidLine.strokeColor = _radarLineColor.CGColor;
        solidLine.fillColor = [UIColor clearColor].CGColor;
        CGPathAddEllipseInRect(solidPath, nil, CGRectMake(self.bounds.size.width*0.5-radius, self.bounds.size.height*0.5-radius, radius*2, radius*2));
        solidLine.path = solidPath;
        CGPathRelease(solidPath);
        [self.layer addSublayer:solidLine];
    }
    
    #pragma mark - 展示
    - (void)showTargetView:(UIView *)targerView {
        self.center = targerView.center;
        [targerView addSubview:self];
    }
    
    #pragma mark - 
    - (void)dismiss {
        [self removeFromSuperview];
    }
    
    #pragma mark - 开始动画
    - (void)startAnimatian {
        if (_radarViewType == RadarViewTypeScan) {
            CABasicAnimation* rotationAnimation;
            rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
            rotationAnimation.toValue = [NSNumber numberWithFloat: 1 * M_PI * 2.0 ];
            rotationAnimation.duration = 2;
            rotationAnimation.cumulative = YES;
            rotationAnimation.repeatCount = INT_MAX;
            [self.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
        } else {
            [self diffuseAnimation];
            _timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(diffuseAnimation) userInfo:nil repeats:YES];
        }
    }
    
    #pragma mark - 结束动画
    - (void)stopAnimation {
        if (_radarViewType == RadarViewTypeScan) {
            [self.layer removeAnimationForKey:@"rotationAnimation"];
        } else {
            [_timer invalidate];
            _timer = nil;
        }
    }
    
    - (UIColor *)colorWithCurrentAngleProportion:(CGFloat)angleProportion {
        NSArray * startRGBA = [self RGBA_WithColor:_startColor];
        NSArray * endRGBA = [self RGBA_WithColor:_endColor];
        CGFloat currentR = [startRGBA[0] floatValue] - ([startRGBA[0] floatValue]-[endRGBA[0] floatValue]) * angleProportion;
        CGFloat currentG = [startRGBA[1] floatValue] - ([startRGBA[1] floatValue]-[endRGBA[1] floatValue]) * angleProportion;
        CGFloat currentB = [startRGBA[2] floatValue] - ([startRGBA[2] floatValue]-[endRGBA[2] floatValue]) * angleProportion;
        CGFloat currentA = [startRGBA[3] floatValue] - ([startRGBA[3] floatValue]-[endRGBA[3] floatValue]) * angleProportion;
        return [UIColor colorWithRed:currentR green:currentG blue:currentB alpha:currentA];
    }
    
    /**
     *  将UIColor对象解析成RGBA 值 的数组
     *
     *  @param color UIColor对象,有RGBA值 初始化的
     *[UIColor colorWithRed:rValue green:gValue blue:bValue alpha:aValue]
     *
     *  @return 包含RGBA值得数组[rValue, gValue, bValue, aValue]
     */
    - (NSArray *)RGBA_WithColor:(UIColor *)color {
        NSString * colorStr = [NSString stringWithFormat:@"%@", color];
        //将RGB值描述分隔成字符串
        NSArray * colorValueArray = [colorStr componentsSeparatedByString:@" "];
        NSString * R = colorValueArray[1];
        NSString * G = colorValueArray[2];
        NSString * B = colorValueArray[3];
        NSString * A = colorValueArray[4];
        return @[R, G, B, A];
    }
    
    /** 画圆 */
    - (UIImage *)drawCircle {
        UIGraphicsBeginImageContext(CGSizeMake(_endRadius*2, _endRadius*2));
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextMoveToPoint(context, CenterX, CenterY);
        CGContextSetFillColorWithColor(context, _circleColor.CGColor);
        CGContextAddArc(context, CenterX, CenterY, _endRadius, 0, -2*M_PI, 1);
        CGContextFillPath(context);
        UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return img;
    }
    
    - (void)diffuseAnimation {
        UIImageView * imgView = [[UIImageView alloc] init];
        imgView.image = [self drawCircle];
        imgView.frame = CGRectMake(0, 0, _startRadius, _startRadius);
        imgView.center = CGPointMake(CenterX, CenterY);
        [self addSubview:imgView];
        
        [UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
            imgView.frame = CGRectMake(0, 0, _endRadius*2, _endRadius*2);
            imgView.center = CGPointMake(CenterX, CenterY);
            imgView.alpha = 0;
        } completion:^(BOOL finished) {
            [imgView removeFromSuperview];
        }];
    }
    
    @end
    


    3. ViewController.m 中使用的代码:

    #import "ViewController.h"
    #import "RadarView.h"
    
    @interface ViewController ()
    
    @property (nonatomic, strong) RadarView * scanRadarView;
    @property (nonatomic, strong) RadarView * diffuseRadarView;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        /** 扫描 类型 RadarView */
    //    _scanRadarView = [RadarView scanRadarViewWithRadius:self.view.bounds.size.width*0.5 angle:400 radarLineNum:5 hollowRadius:0];
        
        /** 扩散 类型 RadarView */
        _diffuseRadarView = [RadarView diffuseRadarViewWithStartRadius:7 endRadius:self.view.bounds.size.width*0.5 circleColor:[UIColor whiteColor]];
    }
    
    - (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
        
    //    [_scanRadarView showTargetView:self.view];
    //    [_scanRadarView startAnimatian];
        
        [_diffuseRadarView showTargetView:self.view];
        [_diffuseRadarView startAnimatian];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
    

    现在定义的是能代码加载使用,等有空了,再封装一些方法能在Storyboard中直接使用。

    展开全文
  • 总结动画的时候编写的练习demo,同时写了下常用的一些动画比如点赞+1,雷达向外辐射效果,看的时候只要修改storyboard 的根控制器名称或打开注释的代码即可
  • iOS雷达和类似水波纹效果的实现

    万次阅读 2015-10-09 15:30:57
    最近项目里面需要用到雷达扫描和水波纹效果,具体来说就是打开应用出现水波纹扩散的效果,点击召唤之后出现雷达扫描效果.效果如下: 首先说下第一个水波纹效果,这个比较容易实现,一组组动画就ok了,上代码: #...

    最近项目里面需要用到雷达扫描和水波纹效果,具体来说就是打开应用出现水波纹扩散的效果,点击召唤之后出现雷达扫描效果.效果如下:
    这里写图片描述
    这里写图片描述
    首先说下第一个水波纹效果,这个比较容易实现,一组组动画就ok了,上代码:
    #import “Radar.h”

    @implementation Radar

    -(void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    [KColor(22, 163, 130) setFill];
    UIRectFill(rect);
    NSInteger pulsingCount = 5;
    double animationDuration = 3;
    CALayer * animationLayer = [CALayer layer];
    for (int i = 0; i < pulsingCount; i++) {
        CALayer * pulsingLayer = [CALayer layer];
        pulsingLayer.frame = CGRectMake(0, 0, rect.size.width, rect.size.height);
        pulsingLayer.borderColor = [UIColor whiteColor].CGColor;
        pulsingLayer.borderWidth = 1;
        pulsingLayer.cornerRadius = rect.size.height / 2;
    
        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;
    
        CABasicAnimation * scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        scaleAnimation.fromValue = @1.4;
        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];
    }
    [self.layer addSublayer:animationLayer];
    

    }
    在对应的controller里面引用:

        self.centerRadarView = [[Radar alloc] initWithFrame:CGRectMake(0, 0, 135, 135)];
        _centerRadarView.center = _radarView.center;
        [self.view addSubview:_centerRadarView];

    至于中间的圆,那就根据需要自定义就好了.
    第二个雷达扫描效果就稍微复杂点了,用了一个github上分享的控件XHRadarView
    感谢作者的开源.
    加上了自己很据项目需要改变的动画效果.

    展开全文
  • iOS雷达波扩散Layer层动画的实现

    千次阅读 2016-10-17 17:51:33
    iOS雷达波扩散动画的实现,该动画是一个基于layer层的动画 /*--------------- 扩散动画 ---------------*/  CALayer * _spreadLayer;  _spreadLayer = [CALayer layer];  CGPoint tempPos = _spreadLayer....

    iOS中雷达波扩散动画的实现,该动画是一个基于layer层的动画

    之前做的一个效果图如下图所示



    现在对之前的做一定的修改,在另一个地方使用,

    看代码,我解释一下有的地方,meHeardView是自定义的TableView的heardView,上面添加了头像Button,人物名称和等级Label。这个动画Layer是把层级关系移动到头像Button的下方,这样不会挡住按钮的显示。config.diyGreenColor,是我用单例写的自定义的颜色,你可以自己设置其他值。


    /*--------------- 扩散动画 ---------------*/

        CALayer * spreadLayer;

        spreadLayer = [CALayer layer];

        CGFloat diameter = 130//扩散的大小

        spreadLayer.bounds = CGRectMake(0,0, diameter, diameter);

        spreadLayer.cornerRadius = diameter/2; //设置圆角变为圆形

        spreadLayer.position = personImageButton.center;

        spreadLayer.backgroundColor = [config.diyGreenColor CGColor];

        [meHeardView.layer insertSublayer:spreadLayer below:personImageButton.layer];//把扩散层放到头像按钮下面

        CAMediaTimingFunction * defaultCurve = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];

        CAAnimationGroup * animationGroup = [CAAnimationGroup animation];

        animationGroup.duration = 3;

        animationGroup.repeatCount = INFINITY;//重复无限次

        animationGroup.removedOnCompletion = NO;

        animationGroup.timingFunction = defaultCurve;

        //尺寸比例动画

        CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale.xy"];

        scaleAnimation.fromValue = @0.7;//开始的大小

        scaleAnimation.toValue = @1.0;//最后的大小

        scaleAnimation.duration = 3;//动画持续时间

        //透明度动画

        CAKeyframeAnimation *opacityAnimation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];

        opacityAnimation.duration = 3;

        opacityAnimation.values = @[@0.4, @0.45,@0];//透明度值的设置

        opacityAnimation.keyTimes = @[@0, @0.2,@1];//关键帧

        opacityAnimation.removedOnCompletion = NO;

        animationGroup.animations = @[scaleAnimation, opacityAnimation];//添加到动画组

        [spreadLayer addAnimation:animationGroup forKey:@"pulse"];

        /*---------------------------------------*/


    动画效果截图,这种动画效果就简单实现了,想要多圈雷达波的,自己循环写几个Layer就可以了。

                     




    展开全文
  • iOS动画都是基于 CALayer 的,每个UIView都对应有一个CALayer。 所以修改UIView的属性所呈现的动画都是CALayer实现的。CALayer不能响应事件。下图是UIView和CALyer的关系 iOS中可以实现动画的方式,...
  • iOS 雷达动画效果实现

    千次阅读 2017-05-22 10:57:07
    链接:点击打开链接
  • 纯代码编写雷达扫描旋转动画,分离程度很高,非常实用
  • iOS雷达iOS RadarChart实现

    千次阅读 2016-07-08 14:12:10
    实现效果 刚拿到设计稿的时候大概看了一眼,当时心里想着放张背景图,然后计算下相应点的坐标,在最上面画一层就OK了,其实一开始实现的时候也确实是这么做的,然后我就日了狗了,发现设计稿上多层五边形的间隔不是...
  • ios-录音雷达动画.zip

    2020-07-18 23:31:04
    录音雷达动画
  • 这里就用Xcode6 Beta4+iOS SDK 8.0开发,如果用ObjC的话,只需把某些语法和调用方式替换一下就可以了。 最终效果: 这效果是从MOV文件转成GIF的,而且CSDN不支持大于2M的图片上传,优酷地址创建基本动画 这效果是...
  • iOS原生二维码扫描,带扫描框,扫描动画, iOS7以上可使用, 页面适配所有机型
  • swift项目中使用超炫的雷达扫描功能 功能如下 超炫的扫描效果 动态添加标注图标/标注图标不超出屏幕/标注图标不重叠 标注点击交互 圈数可动态配置 可设置圈与圈的增量距离 开启和关闭调试日志 使用 导入头文件 ...
  • iOS雷达扫描demo

    千次阅读 2017-02-06 17:26:31
    #import @interface LTIndicatiorView : UIView @property(nonatomic,strong)UIColor *color; @property(nonatomic,assign)float repeatCount; @property(nonatomic,strong)UIColor *borderColor;...
  • 刚接触不久iOS开发,拖拉拽开始学习,代码还没接触过,但还算看的半懂! 做成动画扩散效果,这图不是动态的,是我直接截图下来的; 拿别人的代码自己删改了一些,然后加一些自己理解的注释上去,就成这样了!...
  • iOS 雷达扫描效果 实现

    千次阅读 2016-01-13 18:18:17
    1 rotationAnimation.removedOnCompletion = NO; 2 3 rotationAnimation.fillMode = kCAFillModeForwards;... 比如动画开始之前,动画结束之后。如果是一个动画CAAnimation,则需要将其removedOnCompletio
  • 适用于iOS雷达图表效果 ios Bluetooth ble 蓝牙开发 蓝牙库 蓝牙调式工具 可横竖向滑动的包含24小时时间显示的日历 swift3.0图片浏览器 iOS 精美过度动画源码 iOS...
  • ios 图片旋转 雷达效果
1 2 3 4 5 ... 20
收藏数 1,385
精华内容 554
热门标签
关键字:

雷达动画ios