【问题标题】:swift - present view after entering foregroundswift - 进入前台后显示视图
【发布时间】:2023-03-10 09:34:02
【问题描述】:

我有一个带有登录视图的应用。在 appDelegate 中,我检查用户是否使用密码锁定了应用程序。如果他这样做,他会进入登录视图。 (在 didFinishLaunchingWithOptions 中调用的代码)

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let nav = storyboard.instantiateViewControllerWithIdentifier(Views.LoginVC.rawValue)
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = nav
self.window?.makeKeyAndVisible()

登录后,我在不同的导航控制器中显示实际内容。

let vc = self.storyboard?.instantiateViewControllerWithIdentifier(Views.MainVC.rawValue)
let rootVC = UINavigationController(rootViewController: vc!)
self.presentViewController(rootVC, animated: false, completion: nil)

当关闭应用并再次进入时,appDelegate 会再次检查用户是否使用了密码。如果是,则再次调用第一个代码(我检查过,代码被调用)(从 applicationWillEnterForeground 调用的代码)。但他没有进入登录视图,而是停留在主要内容视图。如果他再次离开,控制台中会弹出一条错误消息。

2016-04-25 20:50:52.714 Point[7222:123809] Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.

我需要更改什么,以便应用在返回时再次显示登录视图?以及如何避免此错误消息?

更新

我刚刚通过从 applicationDidBecomeActive 而不是 didFinishLaunchingWithOptions 调用代码解决了我的问题。我不知道为什么会这样,但它确实有效!

【问题讨论】:

    标签: swift uinavigationcontroller transition appdelegate


    【解决方案1】:

    不,我认为你有一个错误。你应该把你的代码放在applicationWillEnterForeground(),因为你希望你的代码在每次用户运行应用程序时被调用一次。

    应用程序在屏幕上时处于“非活动状态”,但未处于活动状态。例如,如果您双击主页按钮,或者如果您收到警报。每次应用程序从非活动状态转换为活动状态时,都会调用 applicationDidBecomeActive() 方法。

    【讨论】:

    • 感谢您的解释,您的解决方案同样有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多