首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iPad专业版iPadOS 15.0.2方向更改不起作用

iPad专业版iPadOS 15.0.2方向更改不起作用
EN

Stack Overflow用户
提问于 2021-10-14 09:42:35
回答 2查看 384关注 0票数 1

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

只要这个功能在iphone(所有ios版本)上运行良好,我们就会通过编程将方向更改为横向。但屏幕旋转功能在iPad专业版iPadOS 15.0及更高版本上不起作用。我对它进行了调试,旋转状态设置为"orientation“键,但UIViewController.attemptRotationToDeviceOrientation()函数似乎没有将该状态反映给应用程序。

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

环境:

代码语言:javascript
复制
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:

代码语言:javascript
复制
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    return ScreenOrientationManager.shared.currentOrientation
}

RotationManager类:

代码语言:javascript
复制
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*
}

项目设置

代码语言:javascript
复制
<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>
EN

回答 2

Stack Overflow用户

发布于 2021-10-14 10:26:04

你可以将视图控制器的presentationStyle设置为全屏来修复它..!!

票数 0
EN

Stack Overflow用户

发布于 2021-10-16 22:43:22

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

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

UIViewController.attemptRotationToDeviceOrientation()仍然可以工作,但你弄错了,它工作在最高分配层的窗口上(相反,不支持iOS以确保用户设计),这个窗口不是你的应用程序主屏幕的容器窗口。

为了解决你的问题,你需要检查你的项目是否正在使用另一个级别更高的窗口(检查: window.windowLevel)?需要删除或设置该属性以隐藏楼层较高的窗。例如: window.isHidden = true。

干杯。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69568485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档