Skip to content

Commit

Permalink
tvOS launch images are now properly supported.
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Sep 25, 2016
1 parent a8b033d commit 77bacfd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/video/uikit/SDL_uikitappdelegate.h
Expand Up @@ -24,6 +24,7 @@
@interface SDLLaunchScreenController : UIViewController

- (instancetype)init;
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;
- (void)loadView;

@end
Expand Down
34 changes: 21 additions & 13 deletions src/video/uikit/SDL_uikitappdelegate.m
Expand Up @@ -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)) {
Expand All @@ -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;
Expand All @@ -208,14 +212,17 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibB
if ((orientmask & (1 << curorient)) == 0) {
continue;
}
#endif

imagename = dict[@"UILaunchImageName"];
}

if (imagename) {
image = [UIImage imageNamed:imagename];
}
} else {
}
#if !TARGET_OS_TV
else {
imagename = [bundle objectForInfoDictionaryKey:@"UILaunchImageFile"];

if (imagename) {
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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];
Expand Down

0 comments on commit 77bacfd

Please sign in to comment.