我有一个 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/