Fixed orientation issues in the iOS extended launch screen.
authorAlex Szpakowski <slime73@gmail.com>
Sun, 12 Apr 2015 01:50:28 -0300
changeset 9552201f813c650b
parent 9551 950a1a7b4c3c
child 9553 75dca0c33be6
Fixed orientation issues in the iOS extended launch screen.
src/video/uikit/SDL_uikitappdelegate.m
     1.1 --- a/src/video/uikit/SDL_uikitappdelegate.m	Fri Apr 10 23:30:31 2015 -0300
     1.2 +++ b/src/video/uikit/SDL_uikitappdelegate.m	Sun Apr 12 01:50:28 2015 -0300
     1.3 @@ -115,9 +115,7 @@
     1.4      return image;
     1.5  }
     1.6  
     1.7 -@implementation SDLLaunchScreenController {
     1.8 -    UIInterfaceOrientationMask supportedOrientations;
     1.9 -}
    1.10 +@implementation SDLLaunchScreenController
    1.11  
    1.12  - (instancetype)init
    1.13  {
    1.14 @@ -127,18 +125,16 @@
    1.15  
    1.16      NSBundle *bundle = [NSBundle mainBundle];
    1.17      NSString *screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
    1.18 -
    1.19 -    /* Normally we don't want to rotate from the initial orientation. */
    1.20 -    supportedOrientations = (1 << [UIApplication sharedApplication].statusBarOrientation);
    1.21 +    BOOL atleastiOS8 = UIKit_IsSystemVersionAtLeast(8.0);
    1.22  
    1.23      /* Launch screens were added in iOS 8. Otherwise we use launch images. */
    1.24 -    if (screenname && UIKit_IsSystemVersionAtLeast(8.0)) {
    1.25 +    if (screenname && atleastiOS8) {
    1.26          @try {
    1.27              self.view = [bundle loadNibNamed:screenname owner:self options:nil][0];
    1.28          }
    1.29          @catch (NSException *exception) {
    1.30 -            /* iOS displays a blank screen rather than falling back to an image,
    1.31 -             * if a launch screen name is specified but it fails to load. */
    1.32 +            /* If a launch screen name is specified but it fails to load, iOS
    1.33 +             * displays a blank screen rather than falling back to an image. */
    1.34              return nil;
    1.35          }
    1.36      }
    1.37 @@ -216,13 +212,37 @@
    1.38          }
    1.39  
    1.40          if (image) {
    1.41 -            if (image.size.width > image.size.height) {
    1.42 -                supportedOrientations = UIInterfaceOrientationMaskLandscape;
    1.43 -            } else {
    1.44 -                supportedOrientations = UIInterfaceOrientationMaskPortrait;
    1.45 +            UIImageView *view = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    1.46 +            UIImageOrientation imageorient = UIImageOrientationUp;
    1.47 +
    1.48 +            /* Bugs observed / workaround tested in iOS 8.3, 7.1, and 6.1. */
    1.49 +            if (UIInterfaceOrientationIsLandscape(curorient)) {
    1.50 +                if (atleastiOS8 && image.size.width < image.size.height) {
    1.51 +                    /* On iOS 8, portrait launch images displayed in forced-
    1.52 +                     * landscape mode (e.g. a standard Default.png on an iPhone
    1.53 +                     * when Info.plist only supports landscape orientations) need
    1.54 +                     * to be rotated to display in the expected orientation. */
    1.55 +                    if (curorient == UIInterfaceOrientationLandscapeLeft) {
    1.56 +                        imageorient = UIImageOrientationRight;
    1.57 +                    } else if (curorient == UIInterfaceOrientationLandscapeRight) {
    1.58 +                        imageorient = UIImageOrientationLeft;
    1.59 +                    }
    1.60 +                } else if (!atleastiOS8 && image.size.width > image.size.height) {
    1.61 +                    /* On iOS 7 and below, landscape launch images displayed in
    1.62 +                     * landscape mode (e.g. landscape iPad launch images) need
    1.63 +                     * to be rotated to display in the expected orientation. */
    1.64 +                    if (curorient == UIInterfaceOrientationLandscapeLeft) {
    1.65 +                        imageorient = UIImageOrientationLeft;
    1.66 +                    } else if (curorient == UIInterfaceOrientationLandscapeRight) {
    1.67 +                        imageorient = UIImageOrientationRight;
    1.68 +                    }
    1.69 +                }
    1.70              }
    1.71  
    1.72 -            self.view = [[UIImageView alloc] initWithImage:image];
    1.73 +            /* Create the properly oriented image. */
    1.74 +            view.image = [[UIImage alloc] initWithCGImage:image.CGImage scale:image.scale orientation:imageorient];
    1.75 +
    1.76 +            self.view = view;
    1.77          }
    1.78      }
    1.79  
    1.80 @@ -234,9 +254,18 @@
    1.81      /* Do nothing. */
    1.82  }
    1.83  
    1.84 +- (BOOL)shouldAutorotate
    1.85 +{
    1.86 +    /* If YES, the launch image will be incorrectly rotated in some cases. */
    1.87 +    return NO;
    1.88 +}
    1.89 +
    1.90  - (NSUInteger)supportedInterfaceOrientations
    1.91  {
    1.92 -    return supportedOrientations;
    1.93 +    /* We keep the supported orientations unrestricted to avoid the case where
    1.94 +     * there are no common orientations between the ones set in Info.plist and
    1.95 +     * the ones set here (it will cause an exception in that case.) */
    1.96 +    return UIInterfaceOrientationMaskAll;
    1.97  }
    1.98  
    1.99  @end