-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathSpinerLayer.m
56 lines (45 loc) · 1.58 KB
/
SpinerLayer.m
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
//
// SpinerLayer.m
// Example
//
// Created by 东海 on 15/9/2.
// Copyright (c) 2015年 Jonathan Tribouharet. All rights reserved.
//
#import "SpinerLayer.h"
#import <UIKit/UIKit.h>
@implementation SpinerLayer
-(instancetype) initWithFrame:(CGRect)frame{
self = [super init];
if (self) {
CGFloat radius = (CGRectGetHeight(frame) / 2) * 0.5;
self.frame = CGRectMake(0, 0, CGRectGetHeight(frame), CGRectGetHeight(frame));
CGPoint center = CGPointMake(CGRectGetHeight(frame) / 2, CGRectGetMidY(self.bounds));
CGFloat startAngle = 0 - M_PI_2;
CGFloat endAngle = M_PI * 2 - M_PI_2;
BOOL clockwise = true;
self.path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:clockwise].CGPath;
self.fillColor = nil;
self.strokeColor = [UIColor whiteColor].CGColor;
self.lineWidth = 1;
self.strokeEnd = 0.4;
self.hidden = true;
}
return self;
}
-(void)animation{
self.hidden = false;
CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotate.fromValue = 0;
rotate.toValue = @(M_PI * 2);
rotate.duration = 0.4;
rotate.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
rotate.repeatCount = HUGE;
rotate.fillMode = kCAFillModeForwards;
rotate.removedOnCompletion = false;
[self addAnimation:rotate forKey:rotate.keyPath];
}
-(void)stopAnimation{
self.hidden = true;
[self removeAllAnimations];
}
@end