Skip to content

Commit

Permalink
iOS 10: Work around screen bounds orientation bug. Fixes bugs #3465 and
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Aug 19, 2017
1 parent 2dc5d32 commit 3d0f521
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
27 changes: 25 additions & 2 deletions src/video/uikit/SDL_uikitvideo.m
Expand Up @@ -176,16 +176,39 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)
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

#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 screen.bounds;
return frame;
}

/*
Expand Down
3 changes: 2 additions & 1 deletion src/video/uikit/SDL_uikitviewcontroller.m
Expand Up @@ -293,8 +293,9 @@ - (void)keyboardWillShow:(NSNotification *)notification

- (void)keyboardWillHide:(NSNotification *)notification
{
if (!rotatingOrientation)
if (!rotatingOrientation) {
SDL_StopTextInput();
}
[self setKeyboardHeight:0];
}

Expand Down

0 comments on commit 3d0f521

Please sign in to comment.