根据 iOS 和 iPadOS 16 Beta 3 发行说明:- 尝试在 \xc2\xa0 UIDevice \xc2\xa0via\xc2\xa0上设置方向setValue:forKey:\xc2\x80\x99 不受支持且不再有效。相反,他们说使用:preferredInterfaceOrientationForPresentation。
preferredInterfaceOrientationForPresentation就我而言,通过使用或 ,强制视图控制器方向在 iOS 16 beta 中不起作用requestGeometryUpdate。
以前,UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue,\xc2\xa0forKey: "orientation")工作正常。
当我尝试在控制器上仅允许纵向方向时,我总是收到此错误:Error Domain=UISceneErrorDomain Code=101“视图控制器不支持所请求的方向。请求:landscapeLeft;支持:纵向”UserInfo={NSLocalizedDescription=视图控制器不支持所请求的方向。请求:景观左;支持:纵向}
我称这个方法为:
func updateOrientation(orientation: UIInterfaceOrientationMask) {
if #available(iOS 16, *) {
DispatchQueue.main.async {
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
self.setNeedsUpdateOfSupportedInterfaceOrientations()
self.navigationController?.setNeedsUpdateOfSupportedInterfaceOrientations()
windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: orientation)) { error in
print(error)
print(windowScene?.effectiveGeometry )
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
有人面临同样的问题吗?