Skip to content

Commit eb655b2

Browse files
committedJun 29, 2012
support for landscape launch on ipad, major rework
1 parent 6afb755 commit eb655b2

7 files changed

+158
-68
lines changed
 

‎Default-Landscape~ipad.png

45.5 KB
Loading

‎XOSplash.xcodeproj/project.pbxproj

+12-8
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
083276DB1579D1A500E68689 /* XOViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 083276D91579D1A500E68689 /* XOViewController.xib */; };
1818
083276E51579D33900E68689 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 083276E41579D33900E68689 /* MediaPlayer.framework */; };
1919
083276E81579D3CD00E68689 /* XOSplashVideoController.m in Sources */ = {isa = PBXBuildFile; fileRef = 083276E71579D3CD00E68689 /* XOSplashVideoController.m */; };
20-
083276F0157A550500E68689 /* Default-Portrait~ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = 083276EF157A550500E68689 /* Default-Portrait~ipad.png */; };
2120
083276FC157AF31300E68689 /* splash-ipad.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 083276FA157AF31300E68689 /* splash-ipad.mp4 */; };
2221
083276FD157AF31300E68689 /* splash-iphone.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 083276FB157AF31300E68689 /* splash-iphone.mp4 */; };
23-
08327700157AFB0000E68689 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 083276FE157AFA5400E68689 /* Default.png */; };
22+
08B3070C159E3C0500D7F285 /* Default-Landscape~ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = 08B30708159E3C0500D7F285 /* Default-Landscape~ipad.png */; };
23+
08B3070E159E3C0500D7F285 /* Default-Portrait~ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = 08B3070A159E3C0500D7F285 /* Default-Portrait~ipad.png */; };
24+
08B30711159E3CE500D7F285 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 08B30710159E3CE500D7F285 /* Default.png */; };
2425
/* End PBXBuildFile section */
2526

2627
/* Begin PBXFileReference section */
@@ -40,10 +41,11 @@
4041
083276E41579D33900E68689 /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; };
4142
083276E61579D3CD00E68689 /* XOSplashVideoController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XOSplashVideoController.h; sourceTree = "<group>"; };
4243
083276E71579D3CD00E68689 /* XOSplashVideoController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XOSplashVideoController.m; sourceTree = "<group>"; };
43-
083276EF157A550500E68689 /* Default-Portrait~ipad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-Portrait~ipad.png"; sourceTree = "<group>"; };
4444
083276FA157AF31300E68689 /* splash-ipad.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; name = "splash-ipad.mp4"; path = "Resources/splash-ipad.mp4"; sourceTree = "<group>"; };
4545
083276FB157AF31300E68689 /* splash-iphone.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; name = "splash-iphone.mp4"; path = "Resources/splash-iphone.mp4"; sourceTree = "<group>"; };
46-
083276FE157AFA5400E68689 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; };
46+
08B30708159E3C0500D7F285 /* Default-Landscape~ipad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-Landscape~ipad.png"; sourceTree = SOURCE_ROOT; };
47+
08B3070A159E3C0500D7F285 /* Default-Portrait~ipad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-Portrait~ipad.png"; sourceTree = SOURCE_ROOT; };
48+
08B30710159E3CE500D7F285 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Default.png; path = ../Default.png; sourceTree = "<group>"; };
4749
/* End PBXFileReference section */
4850

4951
/* Begin PBXFrameworksBuildPhase section */
@@ -64,8 +66,6 @@
6466
083276B51579D1A500E68689 = {
6567
isa = PBXGroup;
6668
children = (
67-
083276FE157AFA5400E68689 /* Default.png */,
68-
083276EF157A550500E68689 /* Default-Portrait~ipad.png */,
6969
083276CA1579D1A500E68689 /* XOSplash */,
7070
083276C31579D1A500E68689 /* Frameworks */,
7171
083276C11579D1A500E68689 /* Products */,
@@ -121,6 +121,9 @@
121121
083276E11579D22000E68689 /* Resources */ = {
122122
isa = PBXGroup;
123123
children = (
124+
08B30710159E3CE500D7F285 /* Default.png */,
125+
08B30708159E3C0500D7F285 /* Default-Landscape~ipad.png */,
126+
08B3070A159E3C0500D7F285 /* Default-Portrait~ipad.png */,
124127
083276FA157AF31300E68689 /* splash-ipad.mp4 */,
125128
083276FB157AF31300E68689 /* splash-iphone.mp4 */,
126129
);
@@ -181,10 +184,11 @@
181184
files = (
182185
083276CF1579D1A500E68689 /* InfoPlist.strings in Resources */,
183186
083276DB1579D1A500E68689 /* XOViewController.xib in Resources */,
184-
083276F0157A550500E68689 /* Default-Portrait~ipad.png in Resources */,
185187
083276FC157AF31300E68689 /* splash-ipad.mp4 in Resources */,
186188
083276FD157AF31300E68689 /* splash-iphone.mp4 in Resources */,
187-
08327700157AFB0000E68689 /* Default.png in Resources */,
189+
08B3070C159E3C0500D7F285 /* Default-Landscape~ipad.png in Resources */,
190+
08B3070E159E3C0500D7F285 /* Default-Portrait~ipad.png in Resources */,
191+
08B30711159E3CE500D7F285 /* Default.png in Resources */,
188192
);
189193
runOnlyForDeploymentPostprocessing = 0;
190194
};
-246 KB
Binary file not shown.

‎XOSplash/XOAppDelegate.m

+15-8
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,27 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
2121
CGRect frame = [[UIScreen mainScreen] bounds];
2222
self.window = [[UIWindow alloc] initWithFrame:frame];
2323

24-
NSString *videoName = @"splash-iphone";
25-
NSString *imageName = @"Default.png";
24+
NSString *portraitVideoName = @"splash-iphone";
25+
NSString *portraitImageName = @"Default.png";
26+
NSString *landscapeVideoName = @"splash-iphone-landscape";
27+
NSString *landscapeImageName = @"Default-Landscape.png";
2628
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
27-
videoName = @"splash-ipad";
28-
imageName = @"Default-Portrait~ipad.png";
29+
portraitVideoName = @"splash-ipad";
30+
portraitImageName = @"Default-Portrait~ipad.png";
31+
landscapeVideoName = @"splash-ipad-landscape";
32+
landscapeImageName = @"Default-Landscape~ipad.png";
2933
}
3034

3135
// our video
32-
NSURL *url = [[NSBundle mainBundle] URLForResource:videoName withExtension:@"mp4"];
36+
NSURL *portraitUrl = [[NSBundle mainBundle] URLForResource:portraitVideoName withExtension:@"mp4"];
37+
NSURL *landscapeUrl = [[NSBundle mainBundle] URLForResource:landscapeVideoName withExtension:@"mp4"];
3338
// our splash controller
3439
XOSplashVideoController *splashVideoController =
35-
[[XOSplashVideoController alloc] initWithVideoURL:url
36-
imageName:imageName
37-
delegate:self];
40+
[[XOSplashVideoController alloc] initWithVideoPortraitUrl:portraitUrl
41+
portraitImageName:portraitImageName
42+
landscapeUrl:landscapeUrl
43+
landscapeImageName:landscapeImageName
44+
delegate:self];
3845
// we'll start out with the spash view controller in the window
3946
self.window.rootViewController = splashVideoController;
4047

‎XOSplash/XOSplash-Info.plist

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<dict>
1515
<key>CFBundleIconFiles</key>
1616
<array>
17-
<string>Default-Portrait~ipad.png</string>
1817
<string>Default.png</string>
1918
</array>
2019
</dict>
@@ -35,17 +34,24 @@
3534
<string>1.0</string>
3635
<key>LSRequiresIPhoneOS</key>
3736
<true/>
37+
<key>UIInterfaceOrientation</key>
38+
<string>UIInterfaceOrientationPortrait</string>
3839
<key>UIRequiredDeviceCapabilities</key>
3940
<array>
4041
<string>armv7</string>
4142
</array>
4243
<key>UISupportedInterfaceOrientations</key>
4344
<array>
4445
<string>UIInterfaceOrientationPortrait</string>
46+
<string>UIInterfaceOrientationLandscapeLeft</string>
47+
<string>UIInterfaceOrientationLandscapeRight</string>
4548
</array>
4649
<key>UISupportedInterfaceOrientations~ipad</key>
4750
<array>
4851
<string>UIInterfaceOrientationPortrait</string>
52+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
53+
<string>UIInterfaceOrientationLandscapeLeft</string>
54+
<string>UIInterfaceOrientationLandscapeRight</string>
4955
</array>
5056
</dict>
5157
</plist>

‎XOSplash/XOSplashVideoController.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@
5252
* be appropriate for the current device and orientation. The video
5353
* needs to match the screen's resolution and the image should
5454
* be one of the ones configured in the target summary, the
55-
* one that matches the current device and orientation. */
56-
- (id)initWithVideoURL:(NSURL *)url
57-
imageName:(NSString *)imageName
58-
delegate:(NSObject<XOSplashVideoDelegate> *)delegate;
55+
* one that matches the current device and orientation. Orientations
56+
* support will be dictated by the urls and image names passed in. */
57+
- (id)initWithVideoPortraitUrl:(NSURL *)portraitUrl
58+
portraitImageName:(NSString *)portraitImageName
59+
landscapeUrl:(NSURL *)landscapeUrl
60+
landscapeImageName:(NSString *)landscapeImageName
61+
delegate:(NSObject<XOSplashVideoDelegate> *)delegate;
5962

6063
@end

‎XOSplash/XOSplashVideoController.m

+117-47
Original file line numberDiff line numberDiff line change
@@ -10,69 +10,137 @@
1010
#import <MediaPlayer/MediaPlayer.h>
1111

1212
@implementation XOSplashVideoController {
13+
NSURL *_portraitUrl;
14+
NSString *_portraitImageName;
15+
NSURL *_landscapeUrl;
16+
NSString *_landscapeImageName;
1317
MPMoviePlayerController *_player;
1418
UIImageView *_backgroundImageView;
1519
}
1620

1721
@synthesize delegate = _delegate;
1822

19-
- (id)initWithVideoURL:(NSURL *)url
20-
imageName:(NSString *)imageName
23+
- (id)initWithVideoPortraitUrl:(NSURL *)portraitUrl
24+
portraitImageName:(NSString *)portraitImageName
25+
landscapeUrl:(NSURL *)landscapeUrl
26+
landscapeImageName:(NSString *)landscapeImageName
2127
delegate:(NSObject<XOSplashVideoDelegate> *)delegate;
2228
{
29+
NSLog(@"init");
2330
self = [super init];
2431
if (self) {
32+
_portraitUrl = portraitUrl;
33+
_portraitImageName = portraitImageName;
34+
_landscapeUrl = landscapeUrl;
35+
_landscapeImageName = landscapeImageName;
2536
_delegate = delegate;
2637

2738
self.wantsFullScreenLayout = YES;
39+
}
40+
return self;
41+
}
2842

29-
CGRect frame = [[UIScreen mainScreen] bounds];
30-
UIApplication *application = [UIApplication sharedApplication];
31-
UIWindow *window = application.delegate.window;
32-
33-
// put a background image in the window, so that it'll show as soon as the splash
34-
// goes away, this fixes most of the black flash
35-
UIImage *image = [UIImage imageNamed:imageName];
36-
_backgroundImageView = [[UIImageView alloc] initWithImage:image];
37-
CGRect backgroundFrame = frame;
38-
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
39-
// shift the background frame down to account for the 20px cut out of the image
40-
backgroundFrame.origin.y += 20;
41-
backgroundFrame.size.height -= 20;
42-
}
43-
_backgroundImageView.frame = backgroundFrame;
44-
_backgroundImageView.userInteractionEnabled = NO;
45-
[window addSubview:_backgroundImageView];
43+
- (void)viewDidLayoutSubviews
44+
{
45+
NSLog(@"viewDidLayoutSubviews");
46+
[super viewDidLayoutSubviews];
47+
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) {
48+
// this won't be called if we're in portrait button bottom, so we need to call it manually
49+
[self didRotateFromInterfaceOrientation:UIInterfaceOrientationPortrait];
50+
}
51+
}
52+
53+
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
54+
{
55+
if (_backgroundImageView) {
56+
// once we've started don't allow rotates
57+
return NO;
58+
}
59+
switch (toInterfaceOrientation) {
60+
case UIInterfaceOrientationPortrait:
61+
case UIInterfaceOrientationPortraitUpsideDown:
62+
NSLog(@"shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation: portrait");
63+
return _portraitUrl && _portraitImageName;
64+
case UIInterfaceOrientationLandscapeLeft:
65+
case UIInterfaceOrientationLandscapeRight:
66+
NSLog(@"shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation: landscape");
67+
return _landscapeUrl && _landscapeImageName;
68+
}
69+
}
70+
71+
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
72+
NSLog(@"didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation");
73+
74+
CGRect frame = [[UIScreen mainScreen] bounds];
75+
UIApplication *application = [UIApplication sharedApplication];
76+
UIWindow *window = application.delegate.window;
77+
78+
NSURL *url = _portraitUrl;
79+
NSString *imageName = _portraitImageName;
80+
81+
UIInterfaceOrientation orientation = [application statusBarOrientation];
82+
if (UIInterfaceOrientationIsLandscape(orientation)) {
83+
url = _landscapeUrl;
84+
imageName = _landscapeImageName;
4685

47-
_player = [[MPMoviePlayerController alloc] initWithContentURL:url];
48-
// video doesn't need to be shifted down
49-
_player.view.frame = frame;
50-
_player.useApplicationAudioSession = NO;
51-
_player.controlStyle = MPMovieControlStyleNone;
52-
_player.scalingMode = MPMovieScalingModeNone;
53-
// we're going to install it once it's loaded and play it then
54-
_player.shouldAutoplay = NO;
55-
// there's still a little bit of black flash left when the player is inserted
56-
// as it starts to play, adding the splash image to the background of the player
57-
// will get rid of it
58-
UIImageView *playerBackground = [[UIImageView alloc] initWithImage:image];
59-
playerBackground.frame = backgroundFrame;
60-
_player.view.userInteractionEnabled = NO;
61-
[_player.backgroundView addSubview:playerBackground];
62-
63-
// tell us when the video has loaded
64-
[[NSNotificationCenter defaultCenter] addObserver:self
65-
selector:@selector(splashStateDidChange:)
66-
name:MPMoviePlayerLoadStateDidChangeNotification
67-
object:_player];
68-
69-
// tell us when the video has finished playing
70-
[[NSNotificationCenter defaultCenter] addObserver:self
71-
selector:@selector(splashDidFinish:)
72-
name:MPMoviePlayerPlaybackDidFinishNotification
73-
object:_player];
86+
CGFloat tmp = frame.size.width;
87+
frame.size.width = frame.size.height;
88+
frame.size.height = tmp;
89+
tmp = (frame.size.width - frame.size.height) / 2;
90+
frame.origin.x = -tmp;
91+
frame.origin.y = tmp;
92+
CGFloat rotation = orientation == UIInterfaceOrientationLandscapeLeft ? -M_PI_2 : M_PI_2;
93+
window.transform = CGAffineTransformMakeRotation(rotation);
94+
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
95+
window.transform = CGAffineTransformMakeRotation(M_PI);
7496
}
75-
return self;
97+
98+
// put a background image in the window, so that it'll show as soon as the splash
99+
// goes away, this fixes most of the black flash
100+
UIImage *image = [UIImage imageNamed:imageName];
101+
_backgroundImageView = [[UIImageView alloc] initWithImage:image];
102+
CGRect backgroundFrame = frame;
103+
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
104+
// shift the background frame down to account for the 20px cut out of the image
105+
backgroundFrame.origin.y += 20;
106+
backgroundFrame.size.height -= 20;
107+
}
108+
_backgroundImageView.frame = backgroundFrame;
109+
_backgroundImageView.userInteractionEnabled = NO;
110+
[window addSubview:_backgroundImageView];
111+
112+
_player = [[MPMoviePlayerController alloc] initWithContentURL:url];
113+
// video doesn't need to be shifted down
114+
_player.view.frame = frame;
115+
_player.useApplicationAudioSession = NO;
116+
_player.controlStyle = MPMovieControlStyleNone;
117+
_player.scalingMode = MPMovieScalingModeNone;
118+
// we're going to install it once it's loaded and play it then
119+
_player.shouldAutoplay = NO;
120+
// there's still a little bit of black flash left when the player is inserted
121+
// as it starts to play, adding the splash image to the background of the player
122+
// will get rid of it
123+
UIImageView *playerBackground = [[UIImageView alloc] initWithImage:image];
124+
CGSize imageSize = image.size;
125+
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
126+
playerBackground.frame = CGRectMake(0, 20, imageSize.width, imageSize.height);
127+
}
128+
_player.view.userInteractionEnabled = NO;
129+
[_player.backgroundView addSubview:playerBackground];
130+
131+
// tell us when the video has loaded
132+
[[NSNotificationCenter defaultCenter] addObserver:self
133+
selector:@selector(splashStateDidChange:)
134+
name:MPMoviePlayerLoadStateDidChangeNotification
135+
object:_player];
136+
137+
// tell us when the video has finished playing
138+
[[NSNotificationCenter defaultCenter] addObserver:self
139+
selector:@selector(splashDidFinish:)
140+
name:MPMoviePlayerPlaybackDidFinishNotification
141+
object:_player];
142+
143+
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
76144
}
77145

78146
- (void)splashStateDidChange:(NSNotification *)notification
@@ -109,6 +177,8 @@ - (void)splashDidFinish:(NSNotification *)notification
109177
// take our player out of the window, we're done with it
110178
[_player.view removeFromSuperview];
111179
_player = nil;
180+
181+
[UIApplication sharedApplication].delegate.window.transform = CGAffineTransformIdentity;
112182
}
113183

114184
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

0 commit comments

Comments
 (0)
Please sign in to comment.