tvOS launch images are now properly supported.

Alex Szpakowski 2016-09-25 11:46:25 -03:00
parent a8b033d7c4
commit 77bacfd72d
2 changed files with 22 additions and 13 deletions

View File

@ -24,6 +24,7 @@
@interface SDLLaunchScreenController : UIViewController @interface SDLLaunchScreenController : UIViewController
- (instancetype)init; - (instancetype)init;
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;
- (void)loadView; - (void)loadView;
@end @end

View File

@ -155,29 +155,29 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
} }
if (!self.view) { if (!self.view) {
#if !TARGET_OS_TV
NSArray *launchimages = [bundle objectForInfoDictionaryKey:@"UILaunchImages"]; NSArray *launchimages = [bundle objectForInfoDictionaryKey:@"UILaunchImages"];
UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
NSString *imagename = nil; NSString *imagename = nil;
UIImage *image = nil; UIImage *image = nil;
int screenw = (int)([UIScreen mainScreen].bounds.size.width + 0.5); int screenw = (int)([UIScreen mainScreen].bounds.size.width + 0.5);
int screenh = (int)([UIScreen mainScreen].bounds.size.height + 0.5); int screenh = (int)([UIScreen mainScreen].bounds.size.height + 0.5);
#if !TARGET_OS_TV
UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
/* We always want portrait-oriented size, to match UILaunchImageSize. */ /* We always want portrait-oriented size, to match UILaunchImageSize. */
if (screenw > screenh) { if (screenw > screenh) {
int width = screenw; int width = screenw;
screenw = screenh; screenw = screenh;
screenh = width; screenh = width;
} }
#endif
/* Xcode 5 introduced a dictionary of launch images in Info.plist. */ /* Xcode 5 introduced a dictionary of launch images in Info.plist. */
if (launchimages) { if (launchimages) {
for (NSDictionary *dict in launchimages) { for (NSDictionary *dict in launchimages) {
UIInterfaceOrientationMask orientmask = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; NSString *minversion = dict[@"UILaunchImageMinimumOSVersion"];
NSString *minversion = dict[@"UILaunchImageMinimumOSVersion"]; NSString *sizestring = dict[@"UILaunchImageSize"];
NSString *sizestring = dict[@"UILaunchImageSize"];
NSString *orientstring = dict[@"UILaunchImageOrientation"];
/* Ignore this image if the current version is too low. */ /* Ignore this image if the current version is too low. */
if (minversion && !UIKit_IsSystemVersionAtLeast(minversion.doubleValue)) { if (minversion && !UIKit_IsSystemVersionAtLeast(minversion.doubleValue)) {
@ -192,6 +192,10 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
} }
} }
#if !TARGET_OS_TV
UIInterfaceOrientationMask orientmask = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
NSString *orientstring = dict[@"UILaunchImageOrientation"];
if (orientstring) { if (orientstring) {
if ([orientstring isEqualToString:@"PortraitUpsideDown"]) { if ([orientstring isEqualToString:@"PortraitUpsideDown"]) {
orientmask = UIInterfaceOrientationMaskPortraitUpsideDown; orientmask = UIInterfaceOrientationMaskPortraitUpsideDown;
@ -208,6 +212,7 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
if ((orientmask & (1 << curorient)) == 0) { if ((orientmask & (1 << curorient)) == 0) {
continue; continue;
} }
#endif
imagename = dict[@"UILaunchImageName"]; imagename = dict[@"UILaunchImageName"];
} }
@ -215,7 +220,9 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
if (imagename) { if (imagename) {
image = [UIImage imageNamed:imagename]; image = [UIImage imageNamed:imagename];
} }
} else { }
#if !TARGET_OS_TV
else {
imagename = [bundle objectForInfoDictionaryKey:@"UILaunchImageFile"]; imagename = [bundle objectForInfoDictionaryKey:@"UILaunchImageFile"];
if (imagename) { if (imagename) {
@ -226,11 +233,13 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
image = SDL_LoadLaunchImageNamed(@"Default", screenh); image = SDL_LoadLaunchImageNamed(@"Default", screenh);
} }
} }
#endif
if (image) { if (image) {
UIImageView *view = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIImageView *view = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIImageOrientation imageorient = UIImageOrientationUp; UIImageOrientation imageorient = UIImageOrientationUp;
#if !TARGET_OS_TV
/* Bugs observed / workaround tested in iOS 8.3, 7.1, and 6.1. */ /* Bugs observed / workaround tested in iOS 8.3, 7.1, and 6.1. */
if (UIInterfaceOrientationIsLandscape(curorient)) { if (UIInterfaceOrientationIsLandscape(curorient)) {
if (atleastiOS8 && image.size.width < image.size.height) { if (atleastiOS8 && image.size.width < image.size.height) {
@ -254,15 +263,13 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
} }
} }
} }
#endif
/* Create the properly oriented image. */ /* Create the properly oriented image. */
view.image = [[UIImage alloc] initWithCGImage:image.CGImage scale:image.scale orientation:imageorient]; view.image = [[UIImage alloc] initWithCGImage:image.CGImage scale:image.scale orientation:imageorient];
self.view = view; self.view = view;
} }
#else /* !TARGET_OS_TV */
return nil;
#endif
} }
return self; return self;
@ -363,10 +370,11 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
* called), so we show the launch screen programmatically until the first * called), so we show the launch screen programmatically until the first
* time events are pumped. */ * time events are pumped. */
UIViewController *vc = nil; UIViewController *vc = nil;
NSString *screenname = nil;
/* TODO: Try to load the 1080p launch image on tvOS. */ /* tvOS only uses a plain launch image. */
#if !TARGET_OS_TV #if !TARGET_OS_TV
NSString *screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"]; screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
if (screenname && UIKit_IsSystemVersionAtLeast(8.0)) { if (screenname && UIKit_IsSystemVersionAtLeast(8.0)) {
@try { @try {
@ -380,11 +388,11 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
/* Do nothing (there's more code to execute below). */ /* Do nothing (there's more code to execute below). */
} }
} }
#endif
if (vc == nil) { if (vc == nil) {
vc = [[SDLLaunchScreenController alloc] initWithNibName:screenname bundle:bundle]; vc = [[SDLLaunchScreenController alloc] initWithNibName:screenname bundle:bundle];
} }
#endif
if (vc.view) { if (vc.view) {
launchWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; launchWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];