From 77bacfd72d0536e03c067a9cbc1f74d807a05509 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 25 Sep 2016 11:46:25 -0300 Subject: [PATCH] tvOS launch images are now properly supported. --- src/video/uikit/SDL_uikitappdelegate.h | 1 + src/video/uikit/SDL_uikitappdelegate.m | 34 ++++++++++++++++---------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/video/uikit/SDL_uikitappdelegate.h b/src/video/uikit/SDL_uikitappdelegate.h index 5336f71a65cef..edf09f50fc9b1 100644 --- a/src/video/uikit/SDL_uikitappdelegate.h +++ b/src/video/uikit/SDL_uikitappdelegate.h @@ -24,6 +24,7 @@ @interface SDLLaunchScreenController : UIViewController - (instancetype)init; +- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil; - (void)loadView; @end diff --git a/src/video/uikit/SDL_uikitappdelegate.m b/src/video/uikit/SDL_uikitappdelegate.m index 60aeeda4f2591..c94c78a416873 100644 --- a/src/video/uikit/SDL_uikitappdelegate.m +++ b/src/video/uikit/SDL_uikitappdelegate.m @@ -155,29 +155,29 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibB } if (!self.view) { -#if !TARGET_OS_TV NSArray *launchimages = [bundle objectForInfoDictionaryKey:@"UILaunchImages"]; - UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation; NSString *imagename = nil; UIImage *image = nil; int screenw = (int)([UIScreen mainScreen].bounds.size.width + 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. */ if (screenw > screenh) { int width = screenw; screenw = screenh; screenh = width; } +#endif /* Xcode 5 introduced a dictionary of launch images in Info.plist. */ if (launchimages) { for (NSDictionary *dict in launchimages) { - UIInterfaceOrientationMask orientmask = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; - NSString *minversion = dict[@"UILaunchImageMinimumOSVersion"]; - NSString *sizestring = dict[@"UILaunchImageSize"]; - NSString *orientstring = dict[@"UILaunchImageOrientation"]; + NSString *minversion = dict[@"UILaunchImageMinimumOSVersion"]; + NSString *sizestring = dict[@"UILaunchImageSize"]; /* Ignore this image if the current version is too low. */ if (minversion && !UIKit_IsSystemVersionAtLeast(minversion.doubleValue)) { @@ -192,6 +192,10 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibB } } +#if !TARGET_OS_TV + UIInterfaceOrientationMask orientmask = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; + NSString *orientstring = dict[@"UILaunchImageOrientation"]; + if (orientstring) { if ([orientstring isEqualToString:@"PortraitUpsideDown"]) { orientmask = UIInterfaceOrientationMaskPortraitUpsideDown; @@ -208,6 +212,7 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibB if ((orientmask & (1 << curorient)) == 0) { continue; } +#endif imagename = dict[@"UILaunchImageName"]; } @@ -215,7 +220,9 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibB if (imagename) { image = [UIImage imageNamed:imagename]; } - } else { + } +#if !TARGET_OS_TV + else { imagename = [bundle objectForInfoDictionaryKey:@"UILaunchImageFile"]; if (imagename) { @@ -226,11 +233,13 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibB image = SDL_LoadLaunchImageNamed(@"Default", screenh); } } +#endif if (image) { UIImageView *view = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIImageOrientation imageorient = UIImageOrientationUp; +#if !TARGET_OS_TV /* Bugs observed / workaround tested in iOS 8.3, 7.1, and 6.1. */ if (UIInterfaceOrientationIsLandscape(curorient)) { if (atleastiOS8 && image.size.width < image.size.height) { @@ -254,15 +263,13 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibB } } } +#endif /* Create the properly oriented image. */ view.image = [[UIImage alloc] initWithCGImage:image.CGImage scale:image.scale orientation:imageorient]; self.view = view; } -#else /* !TARGET_OS_TV */ - return nil; -#endif } return self; @@ -363,10 +370,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( * called), so we show the launch screen programmatically until the first * time events are pumped. */ 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 - NSString *screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"]; + screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"]; if (screenname && UIKit_IsSystemVersionAtLeast(8.0)) { @try { @@ -380,11 +388,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( /* Do nothing (there's more code to execute below). */ } } +#endif if (vc == nil) { vc = [[SDLLaunchScreenController alloc] initWithNibName:screenname bundle:bundle]; } -#endif if (vc.view) { launchWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];