Merged.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 12 Apr 2015 20:28:28 -0400
changeset 955375dca0c33be6
parent 9550 e32baab8aef9
parent 9552 201f813c650b
child 9554 879f71e1478b
Merged.
     1.1 --- a/src/video/uikit/SDL_uikitappdelegate.m	Fri Apr 10 22:31:52 2015 -0500
     1.2 +++ b/src/video/uikit/SDL_uikitappdelegate.m	Sun Apr 12 20:28:28 2015 -0400
     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
     2.1 --- a/src/video/uikit/SDL_uikitview.m	Fri Apr 10 22:31:52 2015 -0500
     2.2 +++ b/src/video/uikit/SDL_uikitview.m	Sun Apr 12 20:28:28 2015 -0400
     2.3 @@ -77,11 +77,8 @@
     2.4  
     2.5          data.viewcontroller.view = view;
     2.6  
     2.7 -        if (data.uiwindow.rootViewController != data.viewcontroller) {
     2.8 -            data.uiwindow.rootViewController = data.viewcontroller;
     2.9 -        } else if (view) {
    2.10 -            [data.uiwindow addSubview:view];
    2.11 -        }
    2.12 +        data.uiwindow.rootViewController = nil;
    2.13 +        data.uiwindow.rootViewController = data.viewcontroller;
    2.14  
    2.15          [data.uiwindow layoutIfNeeded];
    2.16      }
    2.17 @@ -96,13 +93,13 @@
    2.18          [data.viewcontroller.view removeFromSuperview];
    2.19          data.viewcontroller.view = self;
    2.20  
    2.21 -        if (data.uiwindow.rootViewController != data.viewcontroller) {
    2.22 -            /* The root view controller handles rotation and the status bar.
    2.23 -             * Assigning it also adds the controller's view to the window. */
    2.24 -            data.uiwindow.rootViewController = data.viewcontroller;
    2.25 -        } else {
    2.26 -            [data.uiwindow addSubview:self];
    2.27 -        }
    2.28 +        /* The root view controller handles rotation and the status bar.
    2.29 +         * Assigning it also adds the controller's view to the window. We
    2.30 +         * explicitly re-set it to make sure the view is properly attached to
    2.31 +         * the window. Just adding the sub-view if the root view controller is
    2.32 +         * already correct causes orientation issues on iOS 7 and below. */
    2.33 +        data.uiwindow.rootViewController = nil;
    2.34 +        data.uiwindow.rootViewController = data.viewcontroller;
    2.35  
    2.36          /* The view's bounds may not be correct until the next event cycle. That
    2.37           * might happen after the current dimensions are queried, so we force a