[Commits] SDL: iOS 10: Work around screen bounds orientation bug. Fixes bu...

libsdl.org revision control commits-owner at libsdl.org
Fri Aug 18 19:23:55 PDT 2017


details:   https://hg.libsdl.org/SDL/rev/770196e01af1
changeset: 11327:770196e01af1
user:      Alex Szpakowski <slime73 at gmail.com>
date:      Fri Aug 18 23:23:30 2017 -0300
description:
iOS 10: Work around screen bounds orientation bug. Fixes bugs #3465 and #3505.

diffstat:

 src/video/uikit/SDL_uikitvideo.m          |  27 +++++++++++++++++++++++++--
 src/video/uikit/SDL_uikitviewcontroller.m |   3 ++-
 2 files changed, 27 insertions(+), 3 deletions(-)

diffs (59 lines):

diff -r ba4fe3686323 -r 770196e01af1 src/video/uikit/SDL_uikitvideo.m
--- a/src/video/uikit/SDL_uikitvideo.m	Fri Aug 18 18:16:37 2017 -0700
+++ b/src/video/uikit/SDL_uikitvideo.m	Fri Aug 18 23:23:30 2017 -0300
@@ -176,16 +176,39 @@
 CGRect
 UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
 {
+    CGRect frame = screen.bounds;
+
 #if !TARGET_OS_TV && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0)
     BOOL hasiOS7 = UIKit_IsSystemVersionAtLeast(7.0);
 
     /* The view should always show behind the status bar in iOS 7+. */
     if (!hasiOS7 && !(window->flags & (SDL_WINDOW_BORDERLESS|SDL_WINDOW_FULLSCREEN))) {
-        return screen.applicationFrame;
+        frame = screen.applicationFrame;
     }
 #endif
 
-    return screen.bounds;
+#if !TARGET_OS_TV
+    /* iOS 10 seems to have a bug where, in certain conditions, putting the
+     * device to sleep with the a landscape-only app open, re-orienting the
+     * device to portrait, and turning it back on will result in the screen
+     * bounds returning portrait orientation despite the app being in landscape.
+     * This is a workaround until a better solution can be found.
+     * https://bugzilla.libsdl.org/show_bug.cgi?id=3505
+     * https://bugzilla.libsdl.org/show_bug.cgi?id=3465
+     * https://forums.developer.apple.com/thread/65337 */
+    if (UIKit_IsSystemVersionAtLeast(8.0)) {
+        UIInterfaceOrientation orient = [UIApplication sharedApplication].statusBarOrientation;
+        BOOL isLandscape = UIInterfaceOrientationIsLandscape(orient);
+
+        if (isLandscape != (frame.size.width > frame.size.height)) {
+            float height = frame.size.width;
+            frame.size.width = frame.size.height;
+            frame.size.height = height;
+        }
+    }
+#endif
+
+    return frame;
 }
 
 /*
diff -r ba4fe3686323 -r 770196e01af1 src/video/uikit/SDL_uikitviewcontroller.m
--- a/src/video/uikit/SDL_uikitviewcontroller.m	Fri Aug 18 18:16:37 2017 -0700
+++ b/src/video/uikit/SDL_uikitviewcontroller.m	Fri Aug 18 23:23:30 2017 -0300
@@ -293,8 +293,9 @@
 
 - (void)keyboardWillHide:(NSNotification *)notification
 {
-    if (!rotatingOrientation)
+    if (!rotatingOrientation) {
         SDL_StopTextInput();
+    }
     [self setKeyboardHeight:0];
 }
 


More information about the commits mailing list