1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// KWMSuperLoadingView.m
// iCemarose
//
// Created by HouWeiBin on 2017/1/24.
// Copyright © 2017年 kollway. All rights reserved.
//
#import "KWMSuperLoadingView.h"
#import "ArcToCircleLayer.h"
static CGFloat const kRadius = 12;
static CGFloat const kLineWidth = 1.2;
//static CGFloat const kStep1Duration = 5.0;
static CGFloat const kStep1Duration = 2;
@interface KWMSuperLoadingView ()
@property (nonatomic) ArcToCircleLayer *arcToCircleLayer;
@property (nonatomic) CABasicAnimation *animation;
@end
@implementation KWMSuperLoadingView
- (void)awakeFromNib {
[super awakeFromNib];
}
#pragma mark - public
-(void)initLoadingView{
[self reset];
[self doStep1];
}
- (void)startAnimation {
if(self.arcToCircleLayer && self.animation){
[self.arcToCircleLayer addAnimation:self.animation forKey:nil];
}
}
- (void)stopAnimation{
if(self.arcToCircleLayer && self.animation){
[self.arcToCircleLayer removeAllAnimations];
}
}
-(void)setProgress:(CGFloat)progress{
[self stopAnimation];
if(self.arcToCircleLayer){
if(progress>=1){
self.arcToCircleLayer.progress = -0.0001;
}else{
self.arcToCircleLayer.progress = (progress-1)/2;
}
// end status
}
}
#pragma mark - animation
- (void)reset {
[self.arcToCircleLayer removeFromSuperlayer];
}
- (void)doStep1 {
self.arcToCircleLayer = [ArcToCircleLayer layer];
self.arcToCircleLayer.contentsScale = [UIScreen mainScreen].scale;
[self.layer addSublayer:self.arcToCircleLayer];
self.arcToCircleLayer.bounds = CGRectMake(0, 0, kRadius * 2 + kLineWidth, kRadius * 2 + kLineWidth);
self.arcToCircleLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
// animation
self.arcToCircleLayer.progress = 1; // end status
self.animation = [CABasicAnimation animationWithKeyPath:@"progress"];
self.animation.duration = kStep1Duration;
self.animation.repeatCount = HUGE_VALF;
self.animation.fromValue = @0.0;
self.animation.toValue = @1.0;
}
@end