• POP的Stroke动画


    POP的Stroke动画

    效果

    源码

    https://github.com/YouXianMing/Animations

    //
    //  PopStrokeController.m
    //  Animations
    //
    //  Created by YouXianMing on 15/11/17.
    //  Copyright © 2015年 YouXianMing. All rights reserved.
    //
    
    #import "PopStrokeController.h"
    #import "GCD.h"
    #import "POP.h"
    #import "StrokeCircleLayerConfigure.h"
    
    @interface PopStrokeController ()
    
    @property (nonatomic, strong) CAShapeLayer  *circleShape;
    @property (nonatomic, strong) GCDTimer      *timer;
    
    @end
    
    @implementation PopStrokeController
    
    - (void)viewDidLoad {
        
        [super viewDidLoad];
    }
    
    - (void)setup {
        
        [super setup];
        
        self.circleShape = [CAShapeLayer layer];
        self.circleShape.strokeEnd = 0.f;
        self.circleShape.lineCap   = kCALineCapRound;
        StrokeCircleLayerConfigure *config = [StrokeCircleLayerConfigure new];
        config.lineWidth    = 4.f;
        config.startAngle   = 0;
        config.endAngle     = M_PI * 2;
        config.radius       = 55.f;
        config.circleCenter = self.view.center;
        config.strokeColor  = [UIColor cyanColor];
        [config configCAShapeLayer:self.circleShape];
        [self.view.layer addSublayer:self.circleShape];
        
        _timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]];
    
        [_timer event:^{
            
            CGFloat value1 = arc4random() % 101 / 100.f;
            CGFloat value2 = arc4random() % 101 / 100.f;
            
            POPSpringAnimation *strokeAnimationEnd = [POPSpringAnimation animationWithPropertyNamed:kPOPShapeLayerStrokeEnd];
            strokeAnimationEnd.toValue             = @(value1 > value2 ? value1 : value2);
            strokeAnimationEnd.springBounciness    = 12.f;
            
            POPSpringAnimation *strokeAnimationStart = [POPSpringAnimation animationWithPropertyNamed:kPOPShapeLayerStrokeStart];
            strokeAnimationStart.toValue             = @(value1 < value2 ? value1 : value2);
            strokeAnimationStart.springBounciness    = 12.f;
            
            POPBasicAnimation *strokeAnimationColor  = [POPBasicAnimation animationWithPropertyNamed:kPOPShapeLayerStrokeColor];
            strokeAnimationColor.toValue             = (__bridge id)([self randomColor].CGColor);
            
            [self.circleShape pop_addAnimation:strokeAnimationEnd forKey:@"layerStrokeAnimation"];
            [self.circleShape pop_addAnimation:strokeAnimationStart forKey:@"layerStrokeAnimation1"];
            [self.circleShape pop_addAnimation:strokeAnimationColor forKey:@"layerStrokeAnimation2"];
            
        } timeIntervalWithSecs:1];
        
        [_timer start];
    }
    
    - (UIColor *)randomColor {
    
        return [UIColor colorWithRed:arc4random() % 101 / 100.f
                               green:arc4random() % 101 / 100.f
                                blue:arc4random() % 101 / 100.f
                               alpha:1];
    }
    
    @end

    细节

  • 相关阅读:
    微信小程序开发(十一)获取手机的完整详细信息
    24小时学通Linux内核总结篇(kconfig和Makefile & 讲不出再见)
    24小时学通Linux内核之向内核添加代码
    24小时学通Linux内核之构建Linux内核
    24小时学通Linux内核之电源开和关时都发生了什么
    24小时学通Linux内核之调度和内核同步
    24小时学通Linux内核之有关Linux文件系统实现的问题
    24小时学通Linux内核之如何处理输入输出操作
    24小时学通Linux内核之内存管理方式
    24小时学通Linux内核之进程
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/4971210.html
Copyright © 2020-2023  润新知