iPad Pro iPadOS 15.0.2方向改变不工作



我的应用程序支持iPhone和iPad缩放(不支持iPad全屏)。

当此功能在iphone(所有ios版本)上正常工作时,我们通过编程将方向更改为横向。但屏幕旋转功能在iPad Pro 15.0及以上版本上不起作用。我调试它,旋转状态被设置为"方向"。键,但UIViewController.attemptRotationToDeviceOrientation()函数似乎没有反映状态到应用程序。

下面是执行屏幕旋转的代码。你能帮忙检查一下吗?

环境:

Xcode: 12.2(12B45b), Version 13.0 (13A233)  
Simulator: iPad Pro(12.9-inch) OS15.0 
Device: iPad Pro 11inch (gen2) OS 15.0.2

Appdelegate:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return ScreenOrientationManager.shared.currentOrientation
}

RotationManager类:

class ScreenOrientationManager: NSObject {
static let shared: ScreenOrientationManager = ScreenOrientationManager()
var currentOrientation: UIInterfaceOrientationMask = .portrait 
@discardableResult
func rotateScreen() {
if self.currentOrientation == .portrait {
self.currentOrientation = .landscape
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
} else {
self.currentOrientation = .portrait
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}
UIViewController.attemptRotationToDeviceOrientation() // *→ Not working on iPadOS15*
}

项目设置

<key>UIRequiresFullScreen</key>
<false/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>

你可以设置viewcontroller的presentationStyle为全屏来修复它…!!

你很好,这是一个很好的问题,我代表很多人感谢你。

关于你的情况,我可以具体解释如下:问题是:iPadOS和iOS之间的区别之一在于苹果开发的iPadOS系统的核心支持滑动滑动和分屏视图等功能,这些功能可以同时使用多个不同的应用程序。这意味着管理窗口的公认方式是在ipad屏幕上使用具有相同主活动的多个窗口。

UIViewController.attemptRotationToDeviceOrientation()仍然有效,但你错了,它适用于最高分配层的窗口(iOS反过来不支持以确保用户设计),这个窗口不是容器窗口你的应用程序主屏幕。

要解决您的问题,您需要检查您的项目是否使用另一个窗口,有更高的杠杆(检查:window. windowlevel)?您需要删除或设置该属性以隐藏具有较高楼层的窗口。例如:window。isHidden = true.

欢呼。

最新更新