From 974a7a89c60e9f186edce82a6f29669abfe997be Mon Sep 17 00:00:00 2001
From: bruvzg <7645683+bruvzg@users.noreply.github.com>
Date: Mon, 12 Jun 2023 10:55:26 +0300
Subject: [PATCH] [iOS] Fix orientation change in runtime.
---
doc/classes/DisplayServer.xml | 1 +
platform/ios/display_server_ios.mm | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xml
index c7df5623045..cd39543c453 100644
--- a/doc/classes/DisplayServer.xml
+++ b/doc/classes/DisplayServer.xml
@@ -961,6 +961,7 @@
Sets the [param screen]'s [param orientation]. See also [method screen_get_orientation].
+ [b]Note:[/b] On iOS, this method has no effect if [member ProjectSettings.display/window/handheld/orientation] is not set to [constant SCREEN_SENSOR].
diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm
index 5637931e73b..bfb09b68615 100644
--- a/platform/ios/display_server_ios.mm
+++ b/platform/ios/display_server_ios.mm
@@ -568,6 +568,11 @@ float DisplayServerIOS::screen_get_max_scale() const {
void DisplayServerIOS::screen_set_orientation(DisplayServer::ScreenOrientation p_orientation, int p_screen) {
screen_orientation = p_orientation;
+ if (@available(iOS 16.0, *)) {
+ [AppDelegate.viewController setNeedsUpdateOfSupportedInterfaceOrientations];
+ } else {
+ [UIViewController attemptRotationToDeviceOrientation];
+ }
}
DisplayServer::ScreenOrientation DisplayServerIOS::screen_get_orientation(int p_screen) const {