-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSMFDropShadowControl.m
261 lines (188 loc) · 6.5 KB
/
SMFDropShadowControl.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
//
// SMFDropShadowControl.m
// SMFramework
//
// Created by Kevin Bradley on 9/13/11.
// Copyright 2011 nito, LLC. All rights reserved.
//
#import "SMFDropShadowControl.h"
#import "SMFDefines.h"
#import "SMFMockMenuItem.h"
#import "SMFAnimation.h"
#define ZOOM_TO_POINT CGPointMake(591.5999755859375, 284.39999389648438)
/*
if you are sending from a BRMenuItem there is a proper way to get the current menu item selection
id selectedObject = [[self list] selectedObject];
(keeping in mind this is from your controller you are adding a pop over to)
you also need to set isAnimation to TRUE before adding the controller.
i.e.
SMFListDropShadowControl *c = [[SMFListDropShadowControl alloc]init];
[c setCDelegate:me]; (me being the controller attached to)
[c setSender:sender];
[c setCDatasource:me];
[c setIsAnimated:TRUE];
[c addToController:me];
note: there are a lot of repeat functions between here and SMFListDropShadowControl, hopefully at some point that can become a subclass of this as well
and that code can be pruned out.
this class should NEVER be called directly, its sole purpose is for all other SMFDropShadow subclasses to easily subclass and retain the animation goodness.
*/
@implementation SMFDropShadowControl
@synthesize isAnimated, sender;
-(id)init
{
self =[super init];
if (self!=nil) {
self.isAnimated = FALSE; //up to you, can be false by default if you dont like it
}
return self;
}
- (void)setZoomInPosition
{
CABasicAnimation *pos = [CABasicAnimation animationWithKeyPath:@"position"];
if (sender != nil)
{
pos.fromValue = [NSValue valueWithCGPoint:[sender position]];
} else {
pos.fromValue = [NSValue valueWithCGPoint:ZOOM_TO_POINT]; //
}
pos.toValue = [NSValue valueWithCGPoint:CGPointMake(640.0, 360.0)];
pos.fillMode = kCAFillModeForwards;
[[self layer] addAnimation:pos forKey:@"position"];
}
- (void)setZoomOutPosition
{
CABasicAnimation *pos = [CABasicAnimation animationWithKeyPath:@"position"];
pos.fromValue = [NSValue valueWithCGPoint:CGPointMake(640.0, 360.0)]; //
if (sender != nil)
{
pos.toValue = [NSValue valueWithCGPoint:[sender position]];
} else {
pos.toValue = [NSValue valueWithCGPoint:ZOOM_TO_POINT];
}
pos.fillMode = kCAFillModeForwards;
[[self layer] addAnimation:pos forKey:@"position"];
}
-(BOOL)avoidsCursor //of course it was easier than i was making it!!
{
return TRUE;
}
- (void)removeFromParent
{
if (self.isAnimated == TRUE)
{
//CATransform3D zoomTransform = CATransform3DMakeScale(0.1, 0.1, 1.0);
CAAnimationGroup *zoomOutAnimation = nil;
if (sender != nil)
zoomOutAnimation = [SMFAnimation zoomOutFadedToRect:[sender bounds]];
else
zoomOutAnimation = [SMFAnimation zoomOutFadedToRect:CGRectZero];
[zoomOutAnimation setDelegate:self];
[self setZoomOutPosition];
[zoomOutAnimation setValue:@"removeFromParent" forKey:@"Name"];
[[self layer] addAnimation:zoomOutAnimation forKey:@"removeFromParent"];
} else {
[super removeFromParent];
}
}
-(void)addToController:(BRController *)ctrl
{
CGRect f = CGRectMake(256.0,72.0,768.0,576.0);//(s.width*0.2, s.height*0.1, s.width*0.6, s.height*0.8);
[self setFrame:f];
if (self.isAnimated == TRUE)
{
CAAnimationGroup *zoomInAnimation = nil;
if (sender != nil)
{
[self updateSender]; //fixes the sender to have a proper X value for purposes of zooming in and out
zoomInAnimation = [SMFAnimation zoomInFadedToRect:[sender bounds]];
} else {
zoomInAnimation = [SMFAnimation zoomInFadedToRect:CGRectZero];
}
[self setZoomInPosition]; //wish there was some way for me to implement this into the animation class, but its specific to self
[zoomInAnimation setValue:@"zoomInAnimation" forKey:@"Name"];
[zoomInAnimation setDelegate:self];
[self addAnimation:zoomInAnimation forKey:@"zoomInAnimation"];
}
[ctrl addControl:self];
[ctrl setFocusedControl:self];
//[ctrl _setControlFocused:TRUE];
[ctrl _setFocus:self];
}
- (void)animationDidStart:(CAAnimation *)anim
{
//NSLog(@"animationDidStart: %@", anim);
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
NSString *animationName = [anim valueForKey:@"Name"];
if ([animationName isEqualToString:@"removeFromParent"])
{
[super removeFromParent];
}
[self removeAnimationForKey:animationName];
}
/*
if we are a BRMenuItem there are very minimal chances that you will get a usable position and bounds from it for zooming purposes
here are all the functions where i handle what is mentioned at the top (the comments about sender)
*/
- (void)updateSender
{
if ([sender isKindOfClass:[BRMenuItem class]]) //is or descends from BRMenuItem
{
id newSender = [self synthesizeMockItem]; //create our stub menu item that has 2 variables total.
if (newSender != nil)
{
// NSLog(@"setting new sender to: %@", newSender);
sender = newSender;
//NSLog(@"sender check: %@", sender);
}
}
}
// find the list given the BRMenuItem (or said subclass of BRMenuItem)
- (id)getListFromMenuItem:(id)menuItem
{
id listControl = [[[menuItem parent] parent] parent]; //parent = BRGridControl, grand parent = BRScrollControl, great grand parent = BRListControl
NSString *class = NSStringFromClass([listControl class]);
if (![class isEqualToString:@"BRListControl"])
{
NSLog(@"cant find list control!!!, found %@ instead!", class); //bail!!!
return nil;
}
return listControl;
}
//given the BRBlueGlowSelectionLozengeLayer control, spit out our stub class with the proper positioning.
- (id)synthesizeMockItemFrom:(id)theSender withX:(float)xValue
{
SMFMockMenuItem *menuItem = [[SMFMockMenuItem alloc] init];
CGPoint newPosition = [theSender position];
newPosition.x = xValue; //said attitude adjustment, without setting this x variable properly, all hell breaks loose.
[menuItem setBounds:[theSender bounds]];
[menuItem setPosition:newPosition];
return menuItem;
}
- (id)synthesizeMockItem
{
id theList = [self getListFromMenuItem:sender];
if (theList == nil)
return nil;
CGPoint listPosition = [theList position];
float xValue = listPosition.x;
NSEnumerator *controlEnum = [[theList controls] objectEnumerator];
id current = nil;
while ((current = [controlEnum nextObject]))
{
NSString *currentClass = NSStringFromClass([current class]);
if ([currentClass isEqualToString:@"BRBlueGlowSelectionLozengeLayer"])
{
return [self synthesizeMockItemFrom:current withX:xValue];
}
}
return nil;
}
-(void)dealloc
{
[sender release];
self.sender = nil;
[super dealloc];
}
@end