iOS 10: Work around screen bounds orientation bug. Fixes bugs #3465 and #3505.
authorAlex Szpakowski <slime73@gmail.com>
Fri, 18 Aug 2017 23:23:30 -0300
changeset 11327770196e01af1
parent 11326 ba4fe3686323
child 11328 ff47cfbabe5f
iOS 10: Work around screen bounds orientation bug. Fixes bugs #3465 and #3505.
src/video/uikit/SDL_uikitvideo.m
src/video/uikit/SDL_uikitviewcontroller.m
     1.1 --- a/src/video/uikit/SDL_uikitvideo.m	Fri Aug 18 18:16:37 2017 -0700
     1.2 +++ b/src/video/uikit/SDL_uikitvideo.m	Fri Aug 18 23:23:30 2017 -0300
     1.3 @@ -176,16 +176,39 @@
     1.4  CGRect
     1.5  UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
     1.6  {
     1.7 +    CGRect frame = screen.bounds;
     1.8 +
     1.9  #if !TARGET_OS_TV && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0)
    1.10      BOOL hasiOS7 = UIKit_IsSystemVersionAtLeast(7.0);
    1.11  
    1.12      /* The view should always show behind the status bar in iOS 7+. */
    1.13      if (!hasiOS7 && !(window->flags & (SDL_WINDOW_BORDERLESS|SDL_WINDOW_FULLSCREEN))) {
    1.14 -        return screen.applicationFrame;
    1.15 +        frame = screen.applicationFrame;
    1.16      }
    1.17  #endif
    1.18  
    1.19 -    return screen.bounds;
    1.20 +#if !TARGET_OS_TV
    1.21 +    /* iOS 10 seems to have a bug where, in certain conditions, putting the
    1.22 +     * device to sleep with the a landscape-only app open, re-orienting the
    1.23 +     * device to portrait, and turning it back on will result in the screen
    1.24 +     * bounds returning portrait orientation despite the app being in landscape.
    1.25 +     * This is a workaround until a better solution can be found.
    1.26 +     * https://bugzilla.libsdl.org/show_bug.cgi?id=3505
    1.27 +     * https://bugzilla.libsdl.org/show_bug.cgi?id=3465
    1.28 +     * https://forums.developer.apple.com/thread/65337 */
    1.29 +    if (UIKit_IsSystemVersionAtLeast(8.0)) {
    1.30 +        UIInterfaceOrientation orient = [UIApplication sharedApplication].statusBarOrientation;
    1.31 +        BOOL isLandscape = UIInterfaceOrientationIsLandscape(orient);
    1.32 +
    1.33 +        if (isLandscape != (frame.size.width > frame.size.height)) {
    1.34 +            float height = frame.size.width;
    1.35 +            frame.size.width = frame.size.height;
    1.36 +            frame.size.height = height;
    1.37 +        }
    1.38 +    }
    1.39 +#endif
    1.40 +
    1.41 +    return frame;
    1.42  }
    1.43  
    1.44  /*
     2.1 --- a/src/video/uikit/SDL_uikitviewcontroller.m	Fri Aug 18 18:16:37 2017 -0700
     2.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.m	Fri Aug 18 23:23:30 2017 -0300
     2.3 @@ -293,8 +293,9 @@
     2.4  
     2.5  - (void)keyboardWillHide:(NSNotification *)notification
     2.6  {
     2.7 -    if (!rotatingOrientation)
     2.8 +    if (!rotatingOrientation) {
     2.9          SDL_StopTextInput();
    2.10 +    }
    2.11      [self setKeyboardHeight:0];
    2.12  }
    2.13