gpt4 book ai didi

ios - Swift:在启动时显示登录屏幕时防止闪烁

转载 作者:可可西里 更新时间:2023-11-01 00:59:30 25 4
gpt4 key购买 nike

我们的应用程序中有两个 Storyboard。 Storyboard #1 中的默认 View 假定用户之前提供了有效凭据。如果他们没有这样做,我们将“重定向”到 Storyboard #2 中的登录屏幕:

let storyboard = UIStoryboard(name: "Authentication", bundle: nil)
let controller = storyboard.instantiateViewControllerWithIdentifier("LoginController") as UIViewController
presentViewController(controller, animated: true, completion: nil)

这是有效的 - 但是当此代码运行时会出现闪烁,默认 View 会在显示登录 View 之前短暂出现。如何在不闪烁的情况下执行此操作?

最佳答案

您不必将相应的 ViewController 设置为 Appdelegate 本身中的窗口的 rootviewcontroller,而不是呈现 LoginController,如下所示:

self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
//Check for credentials,if value available make LoginStatus as true
if LoginStatus == true{
//Change Storyboard name "Main" to your "storyboard #1" name.
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
//Change Viecontroller name "My_Offer" to your "DefaultViewController name" name.
let vc = mainStoryboard.instantiateViewControllerWithIdentifier("My_Offer") as UIViewController
let navigationController = UINavigationController(rootViewController: vc)
self.window!.rootViewController = navigationController
}else{
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Authentication", bundle: nil)
let vc = mainStoryboard.instantiateViewControllerWithIdentifier("LoginController") as UIViewController
let navigationController = UINavigationController(rootViewController: vc)
self.window!.rootViewController = navigationController
}
self.window!.makeKeyAndVisible()

这将阻止在呈现 LoginController 之前显示默认 View 。

否则

在 Storyboard #1 中创建一个 DummyViewController(UIViewController) 并将其设为 InitialViewController 并将背景图像(您的启动画面图像)设置为 DummyViewController。在 viewdidload 中检查凭据,如果你有值(value)

let storyboard = UIStoryboard(name: "storyboard #1", bundle: nil)
let controller = storyboard.instantiateViewControllerWithIdentifier("default view ") as UIViewController
presentViewController(controller, animated: true, completion: nil)

如果您给定的代码没有凭证

let storyboard = UIStoryboard(name: "Authentication", bundle: nil)
let controller = storyboard.instantiateViewControllerWithIdentifier("LoginController") as UIViewController
presentViewController(controller, animated: true, completion: nil)

这也可以防止闪烁,但这不是一个好方法。我建议第一种方法设置rootviewcontroller。这可能对你有帮助。试试吧。

关于ios - Swift:在启动时显示登录屏幕时防止闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37336959/

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