相关疑难解决方法(0)

iOS 16 场景方向问题

当我尝试在控制器上仅允许纵向方向时,我总是收到此错误: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)

有人面临同样的问题吗?

portrait orientation ios16 xcode14

15
推荐指数
1
解决办法
2万
查看次数

iOS16+ 横向显示 UIViewController 仅适用于单屏无法工作 [Swift 5.7]

在 iOS 16 之前,横向呈现单屏对于纵向应用来说是可以的。工作代码如下。

备注整个应用程序仅处于纵向模式。

override public var shouldAutorotate: Bool {
    return false
}

override public var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .landscapeLeft
}

override public var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
    return .landscapeLeft
}
Run Code Online (Sandbox Code Playgroud)

我找到了解决方案,但它适用于UIWindowScene,但我需要 UIWindow 中的解决方案。我需要帮助来修复 iOS 16 中的问题。

Xcode - 14.0,iOS - 16.0,模拟器 - 14 Pro

如果有人需要,我可以准备演示。

xcode swift ios16 xcode14 swift5.7

9
推荐指数
2
解决办法
7555
查看次数

标签 统计

ios16 ×2

xcode14 ×2

orientation ×1

portrait ×1

swift ×1

swift5.7 ×1

xcode ×1