src/video/uikit/SDL_uikitappdelegate.m
changeset 9552 201f813c650b
parent 9534 5b2b50804caa
child 9619 b94b6d0bff0f
equal deleted inserted replaced
9551:950a1a7b4c3c 9552:201f813c650b
   113     }
   113     }
   114 
   114 
   115     return image;
   115     return image;
   116 }
   116 }
   117 
   117 
   118 @implementation SDLLaunchScreenController {
   118 @implementation SDLLaunchScreenController
   119     UIInterfaceOrientationMask supportedOrientations;
       
   120 }
       
   121 
   119 
   122 - (instancetype)init
   120 - (instancetype)init
   123 {
   121 {
   124     if (!(self = [super initWithNibName:nil bundle:nil])) {
   122     if (!(self = [super initWithNibName:nil bundle:nil])) {
   125         return nil;
   123         return nil;
   126     }
   124     }
   127 
   125 
   128     NSBundle *bundle = [NSBundle mainBundle];
   126     NSBundle *bundle = [NSBundle mainBundle];
   129     NSString *screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
   127     NSString *screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
   130 
   128     BOOL atleastiOS8 = UIKit_IsSystemVersionAtLeast(8.0);
   131     /* Normally we don't want to rotate from the initial orientation. */
       
   132     supportedOrientations = (1 << [UIApplication sharedApplication].statusBarOrientation);
       
   133 
   129 
   134     /* Launch screens were added in iOS 8. Otherwise we use launch images. */
   130     /* Launch screens were added in iOS 8. Otherwise we use launch images. */
   135     if (screenname && UIKit_IsSystemVersionAtLeast(8.0)) {
   131     if (screenname && atleastiOS8) {
   136         @try {
   132         @try {
   137             self.view = [bundle loadNibNamed:screenname owner:self options:nil][0];
   133             self.view = [bundle loadNibNamed:screenname owner:self options:nil][0];
   138         }
   134         }
   139         @catch (NSException *exception) {
   135         @catch (NSException *exception) {
   140             /* iOS displays a blank screen rather than falling back to an image,
   136             /* If a launch screen name is specified but it fails to load, iOS
   141              * if a launch screen name is specified but it fails to load. */
   137              * displays a blank screen rather than falling back to an image. */
   142             return nil;
   138             return nil;
   143         }
   139         }
   144     }
   140     }
   145 
   141 
   146     if (!self.view) {
   142     if (!self.view) {
   214                 image = SDL_LoadLaunchImageNamed(@"Default", screenh);
   210                 image = SDL_LoadLaunchImageNamed(@"Default", screenh);
   215             }
   211             }
   216         }
   212         }
   217 
   213 
   218         if (image) {
   214         if (image) {
   219             if (image.size.width > image.size.height) {
   215             UIImageView *view = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
   220                 supportedOrientations = UIInterfaceOrientationMaskLandscape;
   216             UIImageOrientation imageorient = UIImageOrientationUp;
   221             } else {
   217 
   222                 supportedOrientations = UIInterfaceOrientationMaskPortrait;
   218             /* Bugs observed / workaround tested in iOS 8.3, 7.1, and 6.1. */
   223             }
   219             if (UIInterfaceOrientationIsLandscape(curorient)) {
   224 
   220                 if (atleastiOS8 && image.size.width < image.size.height) {
   225             self.view = [[UIImageView alloc] initWithImage:image];
   221                     /* On iOS 8, portrait launch images displayed in forced-
       
   222                      * landscape mode (e.g. a standard Default.png on an iPhone
       
   223                      * when Info.plist only supports landscape orientations) need
       
   224                      * to be rotated to display in the expected orientation. */
       
   225                     if (curorient == UIInterfaceOrientationLandscapeLeft) {
       
   226                         imageorient = UIImageOrientationRight;
       
   227                     } else if (curorient == UIInterfaceOrientationLandscapeRight) {
       
   228                         imageorient = UIImageOrientationLeft;
       
   229                     }
       
   230                 } else if (!atleastiOS8 && image.size.width > image.size.height) {
       
   231                     /* On iOS 7 and below, landscape launch images displayed in
       
   232                      * landscape mode (e.g. landscape iPad launch images) need
       
   233                      * to be rotated to display in the expected orientation. */
       
   234                     if (curorient == UIInterfaceOrientationLandscapeLeft) {
       
   235                         imageorient = UIImageOrientationLeft;
       
   236                     } else if (curorient == UIInterfaceOrientationLandscapeRight) {
       
   237                         imageorient = UIImageOrientationRight;
       
   238                     }
       
   239                 }
       
   240             }
       
   241 
       
   242             /* Create the properly oriented image. */
       
   243             view.image = [[UIImage alloc] initWithCGImage:image.CGImage scale:image.scale orientation:imageorient];
       
   244 
       
   245             self.view = view;
   226         }
   246         }
   227     }
   247     }
   228 
   248 
   229     return self;
   249     return self;
   230 }
   250 }
   232 - (void)loadView
   252 - (void)loadView
   233 {
   253 {
   234     /* Do nothing. */
   254     /* Do nothing. */
   235 }
   255 }
   236 
   256 
       
   257 - (BOOL)shouldAutorotate
       
   258 {
       
   259     /* If YES, the launch image will be incorrectly rotated in some cases. */
       
   260     return NO;
       
   261 }
       
   262 
   237 - (NSUInteger)supportedInterfaceOrientations
   263 - (NSUInteger)supportedInterfaceOrientations
   238 {
   264 {
   239     return supportedOrientations;
   265     /* We keep the supported orientations unrestricted to avoid the case where
       
   266      * there are no common orientations between the ones set in Info.plist and
       
   267      * the ones set here (it will cause an exception in that case.) */
       
   268     return UIInterfaceOrientationMaskAll;
   240 }
   269 }
   241 
   270 
   242 @end
   271 @end
   243 
   272 
   244 @implementation SDLUIKitDelegate {
   273 @implementation SDLUIKitDelegate {