forked from soffes/cheddar-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CDIAddTaskAnimationView.m
118 lines (98 loc) · 4 KB
/
CDIAddTaskAnimationView.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// CDIAddTaskAnimationView.m
// Cheddar for iOS
//
// Created by Sam Soffes on 4/29/12.
// Copyright (c) 2012 Nothing Magical. All rights reserved.
//
#import "CDIAddTaskAnimationView.h"
#import "CDITableViewCell.h"
#import "UIFont+CheddariOSAdditions.h"
#import "UIColor+CheddariOSAdditions.h"
#import <QuartzCore/QuartzCore.h>
@implementation CDIAddTaskAnimationView
@synthesize title = _title;
#pragma mark - Animation
- (void)animationToPoint:(CGPoint)point height:(CGFloat)height insertTask:(void(^)(void))insertTask completion:(void(^)(void))completion {
CGSize size = self.bounds.size;
CGFloat cellHeight = [CDITableViewCell cellHeight];
CGFloat topShadowHeight = 6.0f;
CGFloat bottomShadowHeight = 6.0f;
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0.0f, -topShadowHeight, size.width, cellHeight + topShadowHeight + bottomShadowHeight)];
container.alpha = 0.0f;
[self addSubview:container];
// Top shadow
SSGradientView *topShadow = [[SSGradientView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, size.width, topShadowHeight)];
topShadow.backgroundColor = [UIColor clearColor];
topShadow.alpha = 0.0f;
topShadow.colors = [NSArray arrayWithObjects:
[UIColor colorWithWhite:0.0f alpha:0.0f],
[UIColor colorWithWhite:0.0f alpha:0.09f],
nil];
[container addSubview:topShadow];
// Bottom shadow
SSGradientView *bottomShadow = [[SSGradientView alloc] initWithFrame:CGRectMake(0.0f, cellHeight + topShadowHeight, size.width, bottomShadowHeight)];
bottomShadow.backgroundColor = [UIColor clearColor];
bottomShadow.alpha = 0.0f;
bottomShadow.colors = [NSArray arrayWithObjects:
[UIColor colorWithWhite:0.0f alpha:0.13f],
[UIColor colorWithWhite:0.0f alpha:0.0f],
nil];
[container addSubview:bottomShadow];
// Background
SSBorderedView *background = [[SSBorderedView alloc] initWithFrame:CGRectMake(0.0f, topShadowHeight, size.width, cellHeight)];
background.backgroundColor = [UIColor whiteColor];
background.bottomBorderColor = [UIColor colorWithWhite:0.92f alpha:1.0f];
background.contentMode = UIViewContentModeRedraw;
[container addSubview:background];
// Checkbox
UIImageView *checkbox = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"checkbox.png"] stretchableImageWithLeftCapWidth:4 topCapHeight:4]];
checkbox.frame = CGRectMake(-34.0f, 13.0f, 24.0f, 24.0f);
[background addSubview:checkbox];
// Label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(16.0f, 7.0f, size.width - 32.0f, 38.0f)];
label.font = [UIFont cheddarFontOfSize:18.0f];
label.textColor = [UIColor cheddarTextColor];
label.backgroundColor = [UIColor clearColor];
label.text = self.title;
[background addSubview:label];
// Adjust point
point.y = fminf(point.y, size.height);
// Animate
UIViewAnimationOptions options = UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction;
[UIView animateWithDuration:0.2 delay:0.0 options:options animations:^{
container.alpha = 1.0f;
} completion:nil];
NSTimeInterval boxDuration = 0.2f;
NSTimeInterval moveDuration = fmax(0.2, 0.3 * (point.y / height));
[UIView animateWithDuration:boxDuration delay:0.10 options:options animations:^{
topShadow.alpha = 1.0f;
bottomShadow.alpha = 1.0f;
CGRect frame = checkbox.frame;
frame.origin.x = 10.0f;
checkbox.frame = frame;
label.frame = CGRectMake(44.0f, 13.0f, size.width - 54.0f, 24.0f);
label.font = [UIFont cheddarFontOfSize:20.0f];
frame = container.frame;
frame.origin.y += 20.0f;
container.frame = frame;
} completion:^(BOOL finished) {
[UIView animateWithDuration:moveDuration delay:0.0 options:options animations:^{
CGRect frame = container.frame;
frame.origin.y = point.y - topShadowHeight;
container.frame = frame;
} completion:^(BOOL finished) {
if (insertTask) {
insertTask();
}
}];
[UIView animateWithDuration:0.2 delay:moveDuration options:options animations:^{
container.alpha = 0.0f;
} completion:^(BOOL finished) {
if (completion) {
completion();
}
}];
}];
}
@end