iOS 17 强制屏幕旋转仅在 iPAD 上不起作用

问题描述 投票:0回答:1

我已经关注了 Google 和 StackOverFlow 上的所有链接,不幸的是,我找不到任何可靠的解决方案专门针对 iPad 设备

我正在使用 Kodeco UISplitViewController 中的示例代码。您可以从这里下载源代码并添加 UIButton。

我添加了一个按钮并添加了 WindowScene RequestGeometryUpdate 函数的代码。

所以,我需要帮助才能在按下按钮时旋转 iPad 屏幕。我已附上 按下按钮时出现错误控制台消息

我们将非常感谢您的帮助。

@IBAction func btnSelector(_ sender: Any) {
    self.rotateToLandsScapeDevice()
}

func rotateToLandsScapeDevice(){
                                
    let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
    if #available(iOS 16.0, *) {
        windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: .landscapeLeft), errorHandler: { error in
            print("Error", error)
        })
        self.setNeedsUpdateOfSupportedInterfaceOrientations()
    } else {
        // Fallback on earlier versions
        UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
        UIView.setAnimationsEnabled(true)
    }

}

错误控制台消息

Error Domain=UISceneErrorDomain Code=101 "The current windowing mode 
does not allow for programmatic changes to interface orientation." 
UserInfo={NSLocalizedDescription=The current windowing 
mode does not allow for programmatic changes to interface orientation.}
ios swift orientation ios17
1个回答
0
投票

尝试在 info.plist 文件中添加“支持的界面方向(iPhone)”并将该项目设置为“肖像(底部主页按钮)”

© www.soinside.com 2019 - 2024. All rights reserved.