当前位置 博文首页 > xixi:类似 刷新的时候 那个转圈圈 动画

    xixi:类似 刷新的时候 那个转圈圈 动画

    作者:[db:作者] 时间:2021-08-07 18:53

        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(150, 400, 50, 50);
        label.text = @"中";
        label.backgroundColor = [UIColor clearColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:20.0f];
        [self.view addSubview:label];
        
    
        CGPoint point = CGPointMake(label.frame.size.width/2, label.frame.size.width/2);
        CGFloat ra = label.frame.size.width/2;
        CGFloat startAngle = 0;
        CGFloat endAngle = 0.9 * M_PI;
        CGFloat lineWidth = 4;
        
        
        UIBezierPath *path2 = [UIBezierPath bezierPathWithArcCenter:point radius:ra startAngle:startAngle endAngle:2*M_PI clockwise:YES];
        
        CAShapeLayer *shapeLayer2 = [CAShapeLayer layer];
        shapeLayer2.frame = label.bounds;
        shapeLayer2.strokeColor = [UIColor colorWithRed:191/255.0f green:191.0f/255.0f blue:191/255.0f alpha:1].CGColor;
        shapeLayer2.fillColor = [UIColor clearColor].CGColor;
        shapeLayer2.path = path2.CGPath;
        shapeLayer2.lineWidth = lineWidth;
        [label.layer addSublayer:shapeLayer2];
    
        
        UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:point radius:ra startAngle:startAngle endAngle:endAngle clockwise:YES];
        
        
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        shapeLayer.frame = label.bounds;
        shapeLayer.strokeColor = [UIColor colorWithRed:131/255.0f green:131/255.0f blue:131/255.0f alpha:1].CGColor;
        shapeLayer.fillColor = [UIColor clearColor].CGColor;
        shapeLayer.path = path.CGPath;
        shapeLayer.lineWidth = lineWidth;
        [label.layer addSublayer:shapeLayer];
        
        CABasicAnimation *animate = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        animate.byValue = @(M_PI*2);
        animate.duration = 1;
        animate.repeatCount = MAXFLOAT;
        [shapeLayer addAnimation:animate forKey:@"animate"];
    



    cs
    下一篇:没有了