forked from steipete/PSFoundation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MTSplashScreen.m
154 lines (119 loc) · 4.85 KB
/
MTSplashScreen.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
//
// MTSplashScreen.m
// PSFoundation
//
// Created by Matthias Tretter on 03.06.11.
// Copyright 2011 @myell0w. All rights reserved.
//
// Taken from Book iOS Recipes - The Pragmatic Programmers b4: Recipe 1
// Originally Created by Matt Drance on 10/1/10.
// Copyright 2010 Bookhouse Software, LLC. All rights reserved.
//
#import "MTSplashScreen.h"
#import "MTUniversalHelper.h"
@implementation MTSplashScreen
@synthesize splashImage = splashImage_;
@synthesize showsStatusBarOnDismissal = showsStatusBarOnDismissal_;
@synthesize delegate = delegate_;
@synthesize delay = delay_;
////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Lifecycle
////////////////////////////////////////////////////////////////////////
+ (MTSplashScreen *)splashScreen {
MTSplashScreen *splashScreen = [[[MTSplashScreen alloc] initWithNibName:nil bundle:nil] autorelease];
return splashScreen;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
delay_ = 0.;
}
return self;
}
- (void)dealloc {
MCRelease(splashImage_);
[super dealloc];
}
////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark UIView
////////////////////////////////////////////////////////////////////////
- (void)loadView {
UIImageView *iv = [[[UIImageView alloc] initWithImage:self.splashImage] autorelease];
iv.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
iv.contentMode = UIViewContentModeBottom;
self.view = iv;
}
- (void)viewDidUnload {
[super viewDidUnload];
self.splashImage = nil;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if ([self.delegate respondsToSelector:@selector(splashScreenDidAppear:)]) {
[self.delegate splashScreenDidAppear:self];
}
[self performSelector:@selector(hide) withObject:nil afterDelay:self.delay];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if ([self.delegate respondsToSelector:@selector(splashScreenWillDisappear:)]) {
[self.delegate splashScreenWillDisappear:self];
}
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
if ([self.delegate respondsToSelector:@selector(splashScreenDidDisappear:)]) {
[self.delegate splashScreenDidDisappear:self];
}
}
////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Rotation
////////////////////////////////////////////////////////////////////////
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return kRotateOnIPad(toInterfaceOrientation);
}
////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Getter
////////////////////////////////////////////////////////////////////////
- (UIImage *)splashImage {
if (splashImage_ == nil) {
if (isIPad()) {
// first try orientation-specific launch images
if (PSAppStatusBarOrientation == UIInterfaceOrientationPortraitUpsideDown) {
self.splashImage = [UIImage imageNamed:@"Default-PortraitUpsideDown.png"];
} else if (PSAppStatusBarOrientation == UIInterfaceOrientationLandscapeLeft) {
self.splashImage = [UIImage imageNamed:@"Default-LandscapeLeft.png"];
} else if (PSAppStatusBarOrientation == UIInterfaceOrientationLandscapeRight) {
self.splashImage = [UIImage imageNamed:@"Default-LandscapeRight.png"];
}
// if there wasn't found a orientation-specific launch-image
// try the ones for only Portrait/Landscape
if (UIInterfaceOrientationIsPortrait(PSAppStatusBarOrientation)) {
self.splashImage = [UIImage imageNamed:@"Default-Portrait.png"];
} else {
self.splashImage = [UIImage imageNamed:@"Default-Landscape.png"];
}
}
// iPhone, or still no image found on iPad -> use Default.png
if (splashImage_ == nil) {
self.splashImage = [UIImage imageNamed:@"Default.png"];
}
}
return splashImage_;
}
////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark MTSplashScreen
////////////////////////////////////////////////////////////////////////
- (void)hide {
if (self.showsStatusBarOnDismissal) {
UIApplication *app = [UIApplication sharedApplication];
[app setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
}
[self dismissModalViewControllerAnimated:YES];
}
@end