-
Notifications
You must be signed in to change notification settings - Fork 8
/
TAAnimatedDotView.m
executable file
·88 lines (70 loc) · 1.88 KB
/
TAAnimatedDotView.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
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// TAAnimatedDotView.m
// TAPageControl
//
// Created by Tanguy Aladenise on 2015-01-22.
// Copyright (c) 2015 Tanguy Aladenise. All rights reserved.
//
#import "TAAnimatedDotView.h"
static CGFloat const kAnimateDuration = 1;
@implementation TAAnimatedDotView
- (instancetype)init
{
self = [super init];
if (self) {
[self initialization];
}
return self;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initialization];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self initialization];
}
return self;
}
- (void)setDotColor:(UIColor *)dotColor
{
_dotColor = dotColor;
self.layer.borderColor = dotColor.CGColor;
}
- (void)initialization
{
_dotColor = [UIColor whiteColor];
self.backgroundColor = [UIColor clearColor];
self.layer.cornerRadius = CGRectGetWidth(self.frame) / 2;
self.layer.borderColor = [UIColor whiteColor].CGColor;
self.layer.borderWidth = 2;
}
- (void)changeActivityState:(BOOL)active
{
if (active) {
[self animateToActiveState];
} else {
[self animateToDeactiveState];
}
}
- (void)animateToActiveState
{
[UIView animateWithDuration:kAnimateDuration delay:0 usingSpringWithDamping:.5 initialSpringVelocity:-20 options:UIViewAnimationOptionCurveLinear animations:^{
self.backgroundColor = _dotColor;
self.transform = CGAffineTransformMakeScale(1.4, 1.4);
} completion:nil];
}
- (void)animateToDeactiveState
{
[UIView animateWithDuration:kAnimateDuration delay:0 usingSpringWithDamping:.5 initialSpringVelocity:0 options:UIViewAnimationOptionCurveLinear animations:^{
self.backgroundColor = [UIColor clearColor];
self.transform = CGAffineTransformIdentity;
} completion:nil];
}
@end