我已经关注了 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.}