-
Notifications
You must be signed in to change notification settings - Fork 78
/
HySpinerLayer.m
52 lines (45 loc) · 1.57 KB
/
HySpinerLayer.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
//
// SpinerLayer.m
// Example
//
// Created by 东海 on 15/9/2.
// Copyright (c) 2015年 Jonathan Tribouharet. All rights reserved.
//
#import "HySpinerLayer.h"
#import <UIKit/UIKit.h>
@implementation HySpinerLayer
-(instancetype)initWithFrame:(CGRect)frame {
self = [super init];
if (self) {
CGFloat radius = CGRectGetHeight(frame) / 4;
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)beginAnimation {
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