-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArcAnimation.m
executable file
·89 lines (72 loc) · 2.51 KB
/
ArcAnimation.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
89
//
// ArcAnimation.m
//
// Created by Pankaj Taneja on 8/12/14.
// Copyright (c) 2014 Kaiser Permanente. All rights reserved.
//
#import "ArcAnimation.h"
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
@interface ArcAnimation ()
@property (nonatomic, strong) UIView *contentView;
@property (nonatomic, strong) UIView *centerView;
@property (nonatomic, strong) NSArray *items;
@property (nonatomic, assign) NSInteger arcRadius;
@property (nonatomic, assign) CGFloat angle;
@property (nonatomic, assign) CGFloat startingAngle;
@end
@implementation ArcAnimation
- (id)initWithContentView:(UIView *)iContentView
centerItem:(UIView *)iCenterItem
items:(NSArray *)iItems
arcRadius:(NSInteger)iRadius
startingAngle:(CGFloat)iStartingAngle {
if (self = [super init]) {
self.contentView = iContentView;
self.centerView = iCenterItem;
self.items = iItems;
self.arcRadius = iRadius;
self.startingAngle = (iStartingAngle + 180);
CGFloat totalAngle = 180;
CGFloat delta = 0;
if (self.startingAngle > 180) {
delta = self.startingAngle - 180;
}
self.angle = (totalAngle - (delta * 2))/([iItems count] - 1);
}
return self;
}
- (void)expandArc {
for (UIView *aView in self.items) {
aView.hidden = NO;
[aView setCenter:self.centerView.center];
}
[UIView animateWithDuration:.2 animations:^ {
CGFloat increasedAngle = self.startingAngle;
for (UIView *aView in self.items) {
CGFloat angleValue = increasedAngle;
CGPoint aFinalPoint = [self finalPointForItemWithAngle :angleValue];
increasedAngle = angleValue + self.angle;
aView.alpha = 1;
[aView setCenter:aFinalPoint];
}
}completion:^(BOOL iFinished) {
}];
}
- (void)collapseArc {
[UIView animateWithDuration:.3 animations:^ {
for (UIView *aView in self.items) {
aView.alpha = 0;
[aView setCenter:self.centerView.center];
}
}completion:^(BOOL iFinished) {
for (UIView *aView in self.items) {
aView.hidden = YES;
}
}];
}
- (CGPoint)finalPointForItemWithAngle:(CGFloat)iAngle {
CGFloat x = self.arcRadius * cos(DEGREES_TO_RADIANS(iAngle)) + self.centerView.center.x;
CGFloat y = self.arcRadius * sin(DEGREES_TO_RADIANS(iAngle)) + self.centerView.center.y;
return CGPointMake(x, y);
}
@end