gpt4 book ai didi

ios - Swift-无论哪个ViewController启动,在应用启动时都显示showingSplashView

转载 作者:行者123 更新时间:2023-12-01 16:21:08 29 4
gpt4 key购买 nike

在我的应用程序中,我使用的是revealingSplashView

可以登录用户,以便更改起始ViewController:

    class MainNavigationControllerViewController: UINavigationController {

override func viewDidLoad() {
super.viewDidLoad()

if isLoggedIn() {
let homeController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "HomeVC")
viewControllers = [homeController]
}
}

fileprivate func isLoggedIn() -> Bool {
return UserDefaults.standard.isLoggedIn()
}
}

用户尚未登录,因此从用户可以登录并进入 FirstLaunchViewController的位置显示 MainViewController

目前,我以 revealingSplashView形式呈现 FirstLaunchViewController:
let revealingSplashView = RevealingSplashView(iconImage: UIImage(named: "zauberstab")!, iconInitialSize: CGSize(width: 120, height: 120), backgroundColor: .white)

revealingSplashView.startAnimation()

问题是,如果用户登录,我也希望拥有该动画,因此 MainViewController是起始VC。我知道我可以将代码从 FirstLaunchViewController复制到 MainViewController,但这在用户登录并进入 MainViewController时会导致出现问题,即使仅在应用启动后才显示动画。

最佳答案

就像@ chirag90一样,建议的解决方案是将AppDelegate中的代码移动到didFinishLaunchingWithOptions中,如下所示:

var window: UIWindow?

let revealingSplashView = RevealingSplashView(iconImage: UIImage(named: "zauberstab")!, iconInitialSize: CGSize(width: 120, height: 120), backgroundColor: .white)

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
revealingSplashView.startAnimation()
window?.rootViewController?.view.addSubview(revealingSplashView)

return true
}

出现的另一个问题是如何将 reavelingSplashView添加为 Subview,@ matt在此问题中回答了该问题:

adding Subview in AppDelegate

关于ios - Swift-无论哪个ViewController启动,在应用启动时都显示showingSplashView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59899464/

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