ios - 如何在不看到第一个的情况下以模态方式推送两个 View Controller

标签 ios uiviewcontroller segue presentviewcontroller

我想连续显示两个 View Controller ,而不是看到第一个。 我希望能够从第二个返回到第一个。

我已阅读 this post ,但响应集中在使用导航 Controller ,而我想以模态方式呈现第二个 View Controller 。

用例是:我的初始 VC 检查用户是否已登录,如果没有则显示登录 VC。 如果是,则显示主 VC。 注销后,我应该能够放松到登录 VC。

最佳答案

一个合适的解决方案是首先呈现第二个 View Controller ,并且仅在第二个 View Controller 完全出现后才呈现第一个 View Controller 。

初始 View Controller

let secondVc = storyboard!.instantiateViewController(withIdentifier: "Second") as! SecondViewController
secondVc.initialVc = self
present(secondVc, animated: true)

第二 View Controller

fileprivate var firstViewDidAppearTime = true
var initialVc: InitialViewController!

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    if firstViewDidAppearTime {
        firstViewDidAppearTime = false

        let firstVc = storyboard!.instantiateViewController(withIdentifier: "First")
        initialVc.present(firstVc, animated: false)
    }
}

关于ios - 如何在不看到第一个的情况下以模态方式推送两个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48421220/

相关文章:

iphone - 如果父级处于纵向模式,如何在横向模式下加载 UIViewController?

iOS 自定义 Segue - 滑过效果

ios - 重新启动并在 GameScene 中呈现

ios - 为什么我的应用程序没有拾取 Localizable.strings 文件中的文本?

ios - 来自 UNNotificationSound 的声音名称

ios - UIViewController 和 NSURLConnection

iOS - 在 segue 上意外旋转回纵向

ios - UITextField 没有获取属性 swift 4

ios - 如何使用 NSDateFormatter 获取字符串 "Yesterday"?

ios - 我如何通过单击按钮来控制标签栏项目?