udpate
This commit is contained in:
1 parent
e01b51bf37
commit
d84be68f4c
2 files changed
+46
No files matched your search
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// OrientationHelper.swift
|
||||
// Moonlight-ZWM
|
||||
//
|
||||
// Created by ZWM on 2024/7/12.
|
||||
// Copyright © 2024 Moonlight Game Streaming Project. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
import UIKit
|
||||
|
||||
class OrientationHelper {
|
||||
static func updateOrientationToLandscape() {
|
||||
if #available(iOS 16.0, *) {
|
||||
// 调用此方法会使视图控制器重新评估其支持的方向集。
|
||||
UIApplication.shared.keyWindow?.rootViewController?.setNeedsUpdateOfSupportedInterfaceOrientations()
|
||||
|
||||
// 遍历并更新导航控制器的方向
|
||||
if let navigationController = UIApplication.shared.keyWindow?.rootViewController as? UINavigationController {
|
||||
navigationController.setNeedsUpdateOfSupportedInterfaceOrientations()
|
||||
}
|
||||
|
||||
// 尝试更新窗口场景的几何形状为横屏
|
||||
if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
|
||||
let geometryPreferences = UIWindowScene.GeometryPreferences.iOS(interfaceOrientations: .landscape)
|
||||
scene.requestGeometryUpdate(geometryPreferences) { (receivedError: Error?) in
|
||||
if let error = receivedError {
|
||||
// 处理错误
|
||||
print("Error updating window scene geometry: \(error)")
|
||||
} else {
|
||||
// 没有错误,执行后续操作
|
||||
print("Window scene geometry updated successfully.")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 早于 iOS 16.0 的版本的回退逻辑
|
||||
print("iOS version is less than 16.0, falling back to earlier behavior.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user