• 雷达效果


    @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;

    }

     

  • 相关阅读:
    Linux命令:cp (copy)复制文件或目录
    使用 robots.txt 文件阻止或删除网页说明
    ecshop优化修改sitemap.xml到根目录
    我虚拟机上装的CentOS系统显示的ip配置是127.0.0.1,请问如何解决?
    Servlet/JSP vs. ASP.NET MVC
    Ubuntu Linux 上安装Apache的过程
    Ubuntu Linux 上安装Eclipse的过程
    sudo的意义
    Dependency Injection
    Ubuntu Linux 上安装TomCat的过程
  • 原文地址:https://www.cnblogs.com/sgdkg/p/5162750.html
Copyright © 2020-2023  润新知