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;

    }

     

  • 相关阅读:
    根据人脸关键点实现平面三角剖分和最近邻搜索 ( KNN, K=1 ), opencv3.4.2, C++
    KDTree  C++实现
    python 保留小数
    Clion提示:Single-argument constructors must be marked explicitly to avoid unintentional implicit conversions 解法办法
    二叉搜索树的C++ 实现
    排列组合之组合问题 网易深度学习工程师面试题 C++ 使用10方法
    OS X 安装命令行看图工具 chafa 以及其依赖libtool
    leetcode704 C++ 72ms 二分查找
    Deep Interest Network for Click-Through Rate Prediction
    归并排序
  • 原文地址:https://www.cnblogs.com/sgdkg/p/5162750.html
Copyright © 2011-2022 走看看