仿网易评论加载动画

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    CAShapeLayer *layer =[CAShapeLayer layer];
    layer.lineWidth = 10;
    layer.fillColor = [UIColor clearColor].CGColor;
    layer.strokeColor =[UIColor redColor].CGColor;
    layer.frame = CGRectMake(50, 50, 100, 100);
    layer.lineCap = kCALineCapRound;
    
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(50, 50) radius:50 startAngle:DEGREES_TO_RADIANS(270) endAngle:DEGREES_TO_RADIANS(180) clockwise:YES];
    layer.path = path.CGPath;
    [self.view.layer addSublayer:layer];
    
    //画一个圆
    CAKeyframeAnimation *strokeEndAnimation = [CAKeyframeAnimation animationWithKeyPath:@"strokeEnd"];
    strokeEndAnimation.duration = 0.5;
    strokeEndAnimation.values = @[@0.0, @1];
    strokeEndAnimation.keyTimes = @[@0.0,@1];

    //旋转2圈
    CABasicAnimation *rotaAni = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotaAni.fromValue = @(DEGREES_TO_RADIANS(0));
    rotaAni.toValue = @(DEGREES_TO_RADIANS(720));
    rotaAni.autoreverses = YES;

    //最后填充颜色
    //创建一个CABasicAnimation对象
    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    //设置颜色
    animation.toValue=(id)[UIColor blackColor].CGColor; //必须要用黑色

    
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.repeatCount = INFINITY;
    group.duration = 2;
    group.animations = @[strokeEndAnimation,rotaAni,animation];
    

    [layer addAnimation:group forKey:nil];
    
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值