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

标签 ios swift

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

相关文章:

ios - 如何在 objective-c 中将这两个值加在一起

ios - 在 swift 中存储/恢复全局字符串数组时出现问题

objective-c - ios pList 安全

ios - 全屏显示 UIImageView (320*480)

swift - 无法将类型 'String.Type' 的值分配给类型 'String?' - Swift

iphone - 屏幕上的多个 ViewController

ios - 在具有后台功能的 iOS 应用程序中使用重新打开的标准文件描述符?

ios - Rx swift : Need help using flatMap and reduce

swift - 获取正在输入的单词

ios - Swift 中的 HTTP 发送请求参数