-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYXYLoadingLabel.m
More file actions
66 lines (50 loc) · 1.83 KB
/
YXYLoadingLabel.m
File metadata and controls
66 lines (50 loc) · 1.83 KB
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
//
// YXYLoadingLabel.m
// LoadingView
//
// Created by 杨肖宇 on 2017/7/27.
// Copyright © 2017年 yxy. All rights reserved.
//
#import "YXYLoadingLabel.h"
@implementation YXYLoadingLabel{
CAShapeLayer * _shapeLayer;
}
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
[self setup];
}
return self;
}
- (void)setup{
self.textAlignment = NSTextAlignmentCenter;
_shapeLayer = [CAShapeLayer layer];
_shapeLayer.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
[self.layer addSublayer:_shapeLayer];
[self createAnimation];
}
- (void)createAnimation{
CAKeyframeAnimation * rorateAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
rorateAnimation.removedOnCompletion = NO;
rorateAnimation.values = @[@0, @M_PI, @(2 * M_PI)];
rorateAnimation.keyTimes = @[@0.0f, @0.5f, @1.0f];
rorateAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
rorateAnimation.duration = 0.75;
rorateAnimation.repeatCount = HUGE_VALF;
UIBezierPath * path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.frame.size.height / 2, self.frame.size.height / 2) radius:self.frame.size.height / 2 startAngle:0.7 * M_PI endAngle:1.2 * M_PI clockwise:NO];
_shapeLayer.path = path.CGPath;
_shapeLayer.fillColor = [UIColor clearColor].CGColor;
_shapeLayer.strokeColor = self.lineColor.CGColor;
_shapeLayer.lineWidth = 2;
[_shapeLayer addAnimation:rorateAnimation forKey:nil];
}
- (void)setLineColor:(UIColor *)lineColor{
_shapeLayer.strokeColor = lineColor.CGColor;
_lineColor = lineColor;
}
- (void)startAniamtion{
[self createAnimation];
}
- (void)stopAnimation{
[_shapeLayer removeAllAnimations];
}
@end