gpt4 book ai didi

ios - 为什么在状态恢复后更改我的应用程序的方向会关闭我的父 View Controller ?

转载 作者:行者123 更新时间:2023-11-28 08:06:19 25 4
gpt4 key购买 nike

我有一个 View Controller A,它可以模态地呈现 View Controller B 或 View Controller C,这是我们用来捕获签名的屏幕。在 View Controller C 中,我使用以下代码将屏幕旋转为横向:

appDel.shouldRotate = true
let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
UIViewController.attemptRotationToDeviceOrientation()

我在应用委托(delegate)中的什么地方使用

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return shouldRotate ? .landscape : .portrait
}

通常,我可以毫无问题地关闭 View Controller C。但是,如果我恢复应用程序状态并显示 View Controller A 和当前 View Controller C,然后继续关闭 C,应用程序将返回到我们应用程序的主屏幕(初始屏幕),而不是返回到 A。奇怪的事情是我可以在不发生此问题的情况下呈现和关闭 View Controller B。

我已经注释掉了我的屏幕旋转逻辑,我可以毫无问题地关闭 View Controller C。

那么,为什么更改屏幕的方向会阻止我在关闭 C 后返回到 View Controller A?

最佳答案

感谢我与 murphguy 的讨论,我得出结论,这是由于应用程序恢复时导航堆栈未恢复所致。不幸的是,在导航 Controller 中嵌入 VC C 并没有解决问题。为什么navigationController在恢复时用于VC A,我不知道。但是,我在 Why isn't my navigation stack being preserved upon restoring the app? 提出了一个新问题来解决这个问题。 .

关于ios - 为什么在状态恢复后更改我的应用程序的方向会关闭我的父 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44999593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com