-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathIRSplashWindow.m
More file actions
265 lines (118 loc) · 5.52 KB
/
IRSplashWindow.m
File metadata and controls
265 lines (118 loc) · 5.52 KB
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
//
// IRSplashWindow.m
// Tarotie
//
// Created by Evadne Wu on 6/6/10.
// Copyright 2010 Iridia Productions. All rights reserved.
//
#import "IRSplashWindow.h"
@interface IRSplashWindow ()
@property (retain) CALayer *splashLayer;
@property (retain) UIImage *splashImage;
@property (retain) CABasicAnimation *splashRetreatingAnimation;
@property (retain) CABasicAnimation *splashPresentingAnimation;
@end
@interface IRSplashWindow (Private)
- (BOOL) prepareDefaults;
- (void) prepareSplash;
@end
@implementation IRSplashWindow
@synthesize delegate, splashLayer, splashImage, splashPresentingAnimation, splashRetreatingAnimation, splashAnimationDuration, splashRetreated, showSplashWithAnimation, transitionType;
- (IRSplashWindow *) init {
self = [super init];
[self prepareSplash];
return self;
}
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
[self prepareSplash];
}
return self;
}
- (void) awakeFromNib {
[self prepareSplash];
}
- (void) createAnimations {
switch (self.transitionType) {
case IRSplashWindowTransitionTypeFade:
default:
self.splashPresentingAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
self.splashPresentingAnimation.fromValue = [NSNumber numberWithFloat:0.0];
self.splashPresentingAnimation.toValue = [NSNumber numberWithFloat:1.0];
self.splashRetreatingAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
self.splashRetreatingAnimation.fromValue = [NSNumber numberWithFloat:1.0];
self.splashRetreatingAnimation.toValue = [NSNumber numberWithFloat:0.0];
break;
}
[self.splashPresentingAnimation setDelegate:self];
self.splashPresentingAnimation.duration = self.splashAnimationDuration;
self.splashPresentingAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
self.splashPresentingAnimation.fillMode = kCAFillModeForwards;
self.splashPresentingAnimation.removedOnCompletion = NO;
[self.splashPresentingAnimation setValue:IRSplashWindowDefaultSplashPresentingAnimationIdentifierValue forKey:IRSplashWindowDefaultSplashAnimationIdentifierKey];
[self.splashRetreatingAnimation setDelegate:self];
self.splashRetreatingAnimation.duration = self.splashAnimationDuration;
self.splashRetreatingAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
self.splashRetreatingAnimation.fillMode = kCAFillModeForwards;
self.splashRetreatingAnimation.removedOnCompletion = NO;
[self.splashRetreatingAnimation setValue:IRSplashWindowDefaultSplashRetreatingAnimationIdentifierValue forKey:IRSplashWindowDefaultSplashAnimationIdentifierKey];
}
- (BOOL) prepareDefaults {
if (self.splashAnimationDuration == 0)
self.splashAnimationDuration = IRSplashWindowDefaultSplashAnimationDuration;
self.splashImage = [UIImage imageNamed:(NSString *)[[[NSBundle mainBundle] infoDictionary] objectForKey:@"IRSplashWindowImage"]];
if (!self.splashImage) self.splashImage = [UIImage imageNamed:@"Default"];
if (!self.splashImage) {
NSLog(@"ERROR: IRSplashWindow requires the key IRSplashWindowImage be defined in the application’s info dictionary, or a fallback Default.png be used. Neither is present so the window will show without splash.");
return NO;
}
return YES;
}
- (void) prepareSplash {
if (![self prepareDefaults]) return;
if ([self.delegate respondsToSelector:@selector(splashWillPrepare:)])
[(id <IRSplashWindowDelegate>)self.delegate splashWillPrepare:self];
self.userInteractionEnabled = NO;
[self createAnimations];
self.splashLayer = [CALayer layer];
self.splashLayer.bounds = self.frame;
self.splashLayer.position = self.center;
self.splashLayer.zPosition = 512; // Hard-coded default.
// self.splashLayer.backgroundColor = [UIColor clearColor].CGColor;
self.splashLayer.opaque = NO;
self.splashLayer.contents = (id)[self.splashImage CGImage];
self.splashRetreated = YES;
// FIXME: provide mechanism that checks self.showSplashWithAnimation
[self.layer addSublayer:self.splashLayer];
if ([self.delegate respondsToSelector:@selector(splashDidPrepare:)])
[(id <IRSplashWindowDelegate>)self.delegate splashDidPrepare:self];
}
- (void) retreatSplash {
// NSLog(@"IRWindow retreating splash");
if (!self.splashLayer) return;
if ([self.delegate respondsToSelector:@selector(splashWillRetreat:)])
[(id <IRSplashWindowDelegate>)self.delegate splashWillRetreat:self];
[self.splashLayer addAnimation:self.splashRetreatingAnimation forKey:self.splashRetreatingAnimation.keyPath];
}
- (void) animationDidStop:(CABasicAnimation *)theAnimation finished:(BOOL)flag {
NSString *animationIdentifier = (NSString *)[theAnimation valueForKey:IRSplashWindowDefaultSplashAnimationIdentifierKey];
if ([animationIdentifier isEqualToString:IRSplashWindowDefaultSplashRetreatingAnimationIdentifierValue]) {
self.userInteractionEnabled = YES;
if ([self.delegate respondsToSelector:@selector(splashDidRetreat:)])
[(id <IRSplashWindowDelegate>)self.delegate splashDidRetreat:self];
self.splashRetreated = YES;
}
@synchronized (self) {
[self.splashLayer removeAnimationForKey:[theAnimation keyPath]];
[self.splashLayer setValue:[theAnimation toValue] forKeyPath:[theAnimation keyPath]];
}
[self.splashLayer removeFromSuperlayer];
}
- (void)dealloc {
[splashLayer release];
[splashImage release];
[splashRetreatingAnimation release];
[splashPresentingAnimation release];
[super dealloc];
}
@end