From 9a980c9dd42773a655b491713bfc1fb2cf54b4e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Sundstr=C3=B6m?= Date: Wed, 19 Jul 2023 16:58:37 +0200 Subject: [PATCH] IOS7: Fix show/hide of virtual controller in iOS 15 The change in commit 1b3c783b9eebbb3ee784a56db73b0a635328a4c3 assumed that the orientation already had been updated when the system called viewWillTransitionToSize. This seems to be true for iOS 16 while in iOS 15 the orientation seems to be updated a bit later. In iOS 16, make sure that the current orientation is updated when the function viewWillTransitionToSize is called to make sure it's updated when the adjustViewFrameForSafeArea is called. This makes sure that the screen size is updated correctly when forcing the orientation based on the backend user setting. In iOS 15 (and below), set the current orientation when the transition animation finishes to make sure that the interface orientation has been updated to make sure the virtual controller is connected/disconnected properly based on the orientation. --- .../ios7/ios7_scummvm_view_controller.mm | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/backends/platform/ios7/ios7_scummvm_view_controller.mm b/backends/platform/ios7/ios7_scummvm_view_controller.mm index 8acaa4c98ca..576704327b4 100644 --- a/backends/platform/ios7/ios7_scummvm_view_controller.mm +++ b/backends/platform/ios7/ios7_scummvm_view_controller.mm @@ -88,11 +88,26 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; + + // In iOS 16, make sure that the current orientation is updated when the + // function viewWillTransitionToSize is called to make sure it's updated + // when the adjustViewFrameForSafeArea is called. This makes sure that the + // screen size is updated correctly when forcing the orientation based on + // the backend user setting. UIInterfaceOrientation orientationAfter = [self interfaceOrientation]; - if (orientationAfter != UIInterfaceOrientationUnknown && orientationAfter != currentOrientation) { - currentOrientation = orientationAfter; - [[iOS7AppDelegate iPhoneView] interfaceOrientationChanged:currentOrientation]; + if (orientationAfter != UIInterfaceOrientationUnknown) { + [self setCurrentOrientation:orientationAfter]; } + // In iOS 15 (and below), set the current orientation when the transition + // animation finishes to make sure that the interface orientation has been + // updated to make sure the virtual controller is connected/disconnected + // properly based on the orientation. + [coordinator animateAlongsideTransition:nil completion:^(id context) { + UIInterfaceOrientation orientationAfter = [self interfaceOrientation]; + if (orientationAfter != UIInterfaceOrientationUnknown) { + [self setCurrentOrientation:orientationAfter]; + } + }]; } #endif