Workaround for views being in portrait instead of landscape mode on iOS 16

Fixes https://github.com/libsdl-org/SDL/issues/6289
main
Sam Lantinga 2022-11-14 13:03:52 -08:00
parent 9f784b1887
commit a40b7cde10
3 changed files with 38 additions and 1 deletions

View File

@ -69,6 +69,18 @@
CGSize size = self.bounds.size;
size.width *= self.layer.contentsScale;
size.height *= self.layer.contentsScale;
/* Make sure the width/height are oriented correctly
*
* This works around an issue in iOS 16 where the bounds come back in portrait mode
* instead of landscape until the event loop runs.
*/
if ([self shouldSwapDimensions:(size.width >= size.height)]) {
CGFloat temp = size.width;
size.width = size.height;
size.height = temp;
}
((CAMetalLayer *)self.layer).drawableSize = size;
}

View File

@ -35,6 +35,8 @@
- (void)setSDLWindow:(SDL_Window *)window;
- (BOOL)shouldSwapDimensions:(BOOL)portrait;
#if !TARGET_OS_TV && defined(__IPHONE_13_4)
- (UIPointerRegion *)pointerInteraction:(UIPointerInteraction *)interaction regionForRequest:(UIPointerRegionRequest *)request defaultRegion:(UIPointerRegion *)defaultRegion API_AVAILABLE(ios(13.4));
- (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction styleForRegion:(UIPointerRegion *)region API_AVAILABLE(ios(13.4));

View File

@ -120,6 +120,8 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
[data.uiwindow layoutIfNeeded];
}
sdlwindow = window;
/* Add ourself to the new window. */
if (window) {
data = (__bridge SDL_WindowData *) window->driverdata;
@ -144,8 +146,29 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
* layout now to immediately update the bounds. */
[data.uiwindow layoutIfNeeded];
}
}
sdlwindow = window;
- (BOOL)shouldSwapDimensions:(BOOL)landscape
{
#if !TARGET_OS_TV
if (sdlwindow) {
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(sdlwindow);
SDL_DisplayData *displaydata = (__bridge SDL_DisplayData *) display->driverdata;
if (displaydata.uiscreen == [UIScreen mainScreen]) {
NSUInteger orients = UIKit_GetSupportedOrientations(sdlwindow);
BOOL supportsLandscape = (orients & UIInterfaceOrientationMaskLandscape) != 0;
BOOL supportsPortrait = (orients & (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown)) != 0;
/* Make sure the width/height are oriented correctly */
if ((landscape && !supportsLandscape) || (!landscape && !supportsPortrait)) {
return YES;
}
}
}
#endif /* !TARGET_OS_TV */
return NO;
}
#if !TARGET_OS_TV && defined(__IPHONE_13_4)