Merged.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
diff --git a/src/video/uikit/SDL_uikitappdelegate.m b/src/video/uikit/SDL_uikitappdelegate.m
index 2ae6182..19f510e 100644
--- a/src/video/uikit/SDL_uikitappdelegate.m
+++ b/src/video/uikit/SDL_uikitappdelegate.m
@@ -115,9 +115,7 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
return image;
}
-@implementation SDLLaunchScreenController {
- UIInterfaceOrientationMask supportedOrientations;
-}
+@implementation SDLLaunchScreenController
- (instancetype)init
{
@@ -127,18 +125,16 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
NSBundle *bundle = [NSBundle mainBundle];
NSString *screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
-
- /* Normally we don't want to rotate from the initial orientation. */
- supportedOrientations = (1 << [UIApplication sharedApplication].statusBarOrientation);
+ BOOL atleastiOS8 = UIKit_IsSystemVersionAtLeast(8.0);
/* Launch screens were added in iOS 8. Otherwise we use launch images. */
- if (screenname && UIKit_IsSystemVersionAtLeast(8.0)) {
+ if (screenname && atleastiOS8) {
@try {
self.view = [bundle loadNibNamed:screenname owner:self options:nil][0];
}
@catch (NSException *exception) {
- /* iOS displays a blank screen rather than falling back to an image,
- * if a launch screen name is specified but it fails to load. */
+ /* If a launch screen name is specified but it fails to load, iOS
+ * displays a blank screen rather than falling back to an image. */
return nil;
}
}
@@ -216,13 +212,37 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
}
if (image) {
- if (image.size.width > image.size.height) {
- supportedOrientations = UIInterfaceOrientationMaskLandscape;
- } else {
- supportedOrientations = UIInterfaceOrientationMaskPortrait;
+ UIImageView *view = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
+ UIImageOrientation imageorient = UIImageOrientationUp;
+
+ /* Bugs observed / workaround tested in iOS 8.3, 7.1, and 6.1. */
+ if (UIInterfaceOrientationIsLandscape(curorient)) {
+ if (atleastiOS8 && image.size.width < image.size.height) {
+ /* On iOS 8, portrait launch images displayed in forced-
+ * landscape mode (e.g. a standard Default.png on an iPhone
+ * when Info.plist only supports landscape orientations) need
+ * to be rotated to display in the expected orientation. */
+ if (curorient == UIInterfaceOrientationLandscapeLeft) {
+ imageorient = UIImageOrientationRight;
+ } else if (curorient == UIInterfaceOrientationLandscapeRight) {
+ imageorient = UIImageOrientationLeft;
+ }
+ } else if (!atleastiOS8 && image.size.width > image.size.height) {
+ /* On iOS 7 and below, landscape launch images displayed in
+ * landscape mode (e.g. landscape iPad launch images) need
+ * to be rotated to display in the expected orientation. */
+ if (curorient == UIInterfaceOrientationLandscapeLeft) {
+ imageorient = UIImageOrientationLeft;
+ } else if (curorient == UIInterfaceOrientationLandscapeRight) {
+ imageorient = UIImageOrientationRight;
+ }
+ }
}
- self.view = [[UIImageView alloc] initWithImage:image];
+ /* Create the properly oriented image. */
+ view.image = [[UIImage alloc] initWithCGImage:image.CGImage scale:image.scale orientation:imageorient];
+
+ self.view = view;
}
}
@@ -234,9 +254,18 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
/* Do nothing. */
}
+- (BOOL)shouldAutorotate
+{
+ /* If YES, the launch image will be incorrectly rotated in some cases. */
+ return NO;
+}
+
- (NSUInteger)supportedInterfaceOrientations
{
- return supportedOrientations;
+ /* We keep the supported orientations unrestricted to avoid the case where
+ * there are no common orientations between the ones set in Info.plist and
+ * the ones set here (it will cause an exception in that case.) */
+ return UIInterfaceOrientationMaskAll;
}
@end
diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m
index 8bd1f31..84d98fe 100644
--- a/src/video/uikit/SDL_uikitview.m
+++ b/src/video/uikit/SDL_uikitview.m
@@ -77,11 +77,8 @@
data.viewcontroller.view = view;
- if (data.uiwindow.rootViewController != data.viewcontroller) {
- data.uiwindow.rootViewController = data.viewcontroller;
- } else if (view) {
- [data.uiwindow addSubview:view];
- }
+ data.uiwindow.rootViewController = nil;
+ data.uiwindow.rootViewController = data.viewcontroller;
[data.uiwindow layoutIfNeeded];
}
@@ -96,13 +93,13 @@
[data.viewcontroller.view removeFromSuperview];
data.viewcontroller.view = self;
- if (data.uiwindow.rootViewController != data.viewcontroller) {
- /* The root view controller handles rotation and the status bar.
- * Assigning it also adds the controller's view to the window. */
- data.uiwindow.rootViewController = data.viewcontroller;
- } else {
- [data.uiwindow addSubview:self];
- }
+ /* The root view controller handles rotation and the status bar.
+ * Assigning it also adds the controller's view to the window. We
+ * explicitly re-set it to make sure the view is properly attached to
+ * the window. Just adding the sub-view if the root view controller is
+ * already correct causes orientation issues on iOS 7 and below. */
+ data.uiwindow.rootViewController = nil;
+ data.uiwindow.rootViewController = data.viewcontroller;
/* The view's bounds may not be correct until the next event cycle. That
* might happen after the current dimensions are queried, so we force a