-
Notifications
You must be signed in to change notification settings - Fork 5
/
ImageSpinner.m
75 lines (60 loc) · 1.49 KB
/
ImageSpinner.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// SyncActivityIndicator.m
// Miso
//
// Created by Joshua Wu on 7/13/11.
// Copyright 2011 GoMiso, Inc. All rights reserved.
//
#import "ImageSpinner.h"
@interface ImageSpinner ()
- (void)configure;
- (void)repeatAnimation;
@end
@implementation ImageSpinner
- (id)initWithImage:(UIImage *)image {
if ((self = [super initWithImage:image])) {
[self configure];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
[self configure];
}
return self;
}
- (void)configure {
_rotationAngle = 0;
self.userInteractionEnabled = NO;
}
- (void)startAnimating {
if(_animate || _rotationAngle != 0) {
return;
}
_animate = YES;
[self repeatAnimation];
}
- (void)repeatAnimation {
_rotationAngle += M_PI / 2.f;
if(_rotationAngle == 2.f * M_PI) {
_rotationAngle = 0.f;
}
if (_animate || _rotationAngle != M_PI / 2.f) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDidStopSelector:@selector(repeatAnimation)];
self.transform = CGAffineTransformMakeRotation(_rotationAngle);
[UIView commitAnimations];
} else {
_rotationAngle = 0.f;
}
}
- (BOOL)isAnimating {
return _animate;
}
- (void)stopAnimating {
_animate = NO;
}
@end