我一直在使用以下方法来检测iOS 14/15中的当前界面方向:
UIApplication.shared.windows.first!.windowScene!.interfaceOrientation
现在在iOS 16 Beta(1和2)中,它报告错误。风景被报告为颠倒的肖像。
kqqjbcuj1#
if #available(iOS 16, *) { DispatchQueue.main.async { let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene self.setNeedsUpdateOfSupportedInterfaceOrientations() self.navigationController?.setNeedsUpdateOfSupportedInterfaceOrientations() windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: .landscape)) { error in print(error) print(windowScene?.effectiveGeometry ?? "") } } } else { appDelegate.myOrientation = .landscape UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation") UIView.setAnimationsEnabled(true) }
Apple在iOS_16中弃用了UIDevice方向相关的API,而是使用requestGeometryUpdate方法,该方法请求更新窗口场景的几何形状。有关详细信息,请查看以下苹果开发人员文档。requestGeometryUpdate如果您仍然无法成功旋转器械,请查看以下链接以了解可能的根本原因和解决方案。UISceneErrorDomain Code=101 issue and solution
zzoitvuj2#
我设法用这样的方式处理它:
if (@available(iOS 16, *)) { float windowWidth = gameScene.view.window.frame.size.width; float windowHeight = gameScene.view.window.frame.size.height; if (windowWidth > windowHeight) { orientation = UIInterfaceOrientationLandscapeLeft; } else { orientation = UIInterfaceOrientationPortrait; } } else { orientation = gameScene.view.window.windowScene.interfaceOrientation; }
2条答案
按热度按时间kqqjbcuj1#
Apple在iOS_16中弃用了UIDevice方向相关的API,而是使用requestGeometryUpdate方法,该方法请求更新窗口场景的几何形状。
有关详细信息,请查看以下苹果开发人员文档。requestGeometryUpdate
如果您仍然无法成功旋转器械,请查看以下链接以了解可能的根本原因和解决方案。
UISceneErrorDomain Code=101 issue and solution
zzoitvuj2#
我设法用这样的方式处理它: