由于我的应用得到了所有方向的支持.我想只将肖像模式锁定到特定的UIViewController.
(例如,假设它是Tabbed应用程序,当SignIn View以模态方式出现时,我只想将SignIn View设置为纵向模式,无论用户如何旋转设备或当前设备方向如何)
当我尝试在控制器上仅允许纵向方向时,我总是收到此错误: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 )
                }
            }
        }
    }
有人面临同样的问题吗?
我正在制作带有视频播放器的应用程序,除了这个视频播放器之外,我的整个结构仅用于纵向视图。我想仅为该视图启用横向旋转。但我查过很多论坛,每个答案都是向 App Delegate 添加一些代码,但我没有。那我能做什么呢。