swift - 进入前景后的当前视图

时间:2016-04-25 19:09:20

标签: swift uinavigationcontroller transition appdelegate

我有一个带登录视图的应用。在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来解决我的问题。我不知道为什么会这样,但它确实有效!

1 个答案:

答案 0 :(得分:0)

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

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

enter image description here