gpt4 book ai didi

ios - 在没有底层 flash 的情况下,如何在 View 出现之前执行 Segue?

转载 作者:行者123 更新时间:2023-11-28 09:13:47 26 4
gpt4 key购买 nike

我正在检查用户是否已登录。如果已登录,则跳过 LoginViewController(初始 View Controller ),转到 MainViewController。

我已经尝试在 LoginViewController 生命周期的无数地方进行此检查,而没有底层闪烁。

通过底层闪烁,我的意思是您可以在 MainViewController 出现之前的一瞬间看到 LoginViewController。

我已经解决了这 1 种方法,但感觉非常 hacky:

在我的 LoginViewController 中:

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

calls++

if calls == 2 && NSUserDefaults.standardUserDefaults().objectForKey("AuthToken") != nil {
self.performSegueWithIdentifier("loginUserNoAnim", sender: self)
}
}

“loginUserNoAnim”是我创建的没有动画的自定义 Segue。

viewDidLayoutSubviews()在我的代码中被调用 3 次。前两次,我收到警告说我的 ViewController 不在类似于此的窗口层次结构中:Warning: Attempt to present <PSLoginViewController: 0x1fda2b40> on <PSViewController: 0x1fda0720> whose view is not in the window hierarchy!这会在 UI 中创建两个非常快速的白色闪烁。我通过检查通过 call 调用了多少电话来摆脱了它们变量。

现在,这是 100% 的 hacky,是 Not Acceptable 。

有没有办法通过使用 iOS 生命周期来解决这个问题?我什至尝试过使用 appdelegate 方法:

 func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

但我还是看到了下层闪光。缓解它的最佳方法是什么?

最佳答案

我认为以下 StackOverflow 答案很好地解释了如何在应用程序启动时在登录和主视图 Controller 之间切换:

Programmatically set the initial view controller using Storyboards

请注意,如果您在应用程序中提供注销功能,那么您应该将用户引导至登录 View Controller ,因为它仅在应用程序启动时被检查。

关于ios - 在没有底层 flash 的情况下,如何在 View 出现之前执行 Segue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28425527/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com