zoukankan      html  css  js  c++  java
  • 雷达效果

    @interface ViewController ()

    {

        CALayer *_layer;

        CAAnimationGroup *_animaTionGroup;

        CADisplayLink *_disPlayLink;

    }

     

    @end

     

    @implementation ViewController

     

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view, typically from a nib.

    }

     

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

    - (void)startAnimation

    {

        CALayer *layer = [[CALayer alloc] init];

        layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/2;

        layer.frame = CGRectMake(0, 0, layer.cornerRadius * 2, layer.cornerRadius * 2);

        layer.position = self.view.layer.position;

        UIColor *color = [UIColor colorWithRed:arc4random()%10*0.1 green:arc4random()%10*0.1 blue:arc4random()%10*0.1 alpha:1];

        layer.backgroundColor = color.CGColor;

        [self.view.layer addSublayer:layer];

        

        CAMediaTimingFunction *defaultCurve = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];

        

        _animaTionGroup = [CAAnimationGroup animation];

        _animaTionGroup.delegate = self;

        _animaTionGroup.duration = 2;

        _animaTionGroup.removedOnCompletion = YES;

        _animaTionGroup.timingFunction = defaultCurve;

        

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

        scaleAnimation.fromValue = @0.0;

        scaleAnimation.toValue = @1.0;

        scaleAnimation.duration = 2;

        

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

        opencityAnimation.duration = 2;

        opencityAnimation.values = @[@0.8,@0.4,@0.0];

        opencityAnimation.keyTimes = @[@0,@0.5,@1];

        opencityAnimation.removedOnCompletion = YES;

        

        NSArray *animations = @[scaleAnimation,opencityAnimation];

        _animaTionGroup.animations = animations;

        [layer addAnimation:_animaTionGroup forKey:nil];

        

        [self performSelector:@selector(removeLayer:) withObject:layer afterDelay:1.5];

    }

     

    - (void)removeLayer:(CALayer *)layer

    {

        [layer removeFromSuperlayer];

    }

     

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

    {

        _disPlayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(delayAnimation)];

        _disPlayLink.frameInterval = 40;

        [_disPlayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

    }

     

    - (void)delayAnimation

    {

        [self startAnimation];

    }

     

    - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

    {

        [self.view.layer removeAllAnimations];

        [_disPlayLink invalidate];

        _disPlayLink = nil;

    }

     

  • 相关阅读:
    Vue项目里添加特殊字体或 某些字体乱码的问题
    Vue 事件修饰符
    js 判断是什么浏览器、是否为谷歌浏览器
    Vue 打印预览功能
    Vue v-if与v-show的区别
    js 下载文件/导出
    使用Mysql Workbench 导入数据库提示 ERROR 1227 (42000) at line 18: Access denied; you need (at least one of) the SUPER privilege(s) for
    java 使用注释校验数据有效性
    java poi分批次导入Excel
    浅谈java中源码常见的几个关键字(native,strictfp,transient,volatile)
  • 原文地址:https://www.cnblogs.com/sgdkg/p/5162750.html
Copyright © 2011-2022 走看看