当我尝试在控制器上仅允许纵向方向时,我总是收到此错误: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)
有人面临同样的问题吗?