【问题标题】:Swift - show revealingSplashView when app launches no matter which ViewControllerSwift - 无论哪个 ViewController 在应用程序启动时显示revealingSplashView
【发布时间】:2020-01-24 15:31:30
【问题描述】:

在我的应用中,我使用的是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

目前我在FirstLaunchViewController 中展示revealingSplashView,如下所示:

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

revealingSplashView.startAnimation()

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

【问题讨论】:

  • 为什么不直接将 appDelegate 中的 revealingSplashView 代码移动到 didFinishLaunch 中,这样它就会一直被调用。用户是否登录。
  • 我究竟是如何实现这个的?我尝试在didFinishLaunchingWithOptions 中添加这两行,但这没有任何作用
  • 这是我的 git:github.com/DieGlueckswurst/Wishlist 如果有帮助的话

标签: ios swift animation uiview uiviewcontroller


【解决方案1】:

像@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

【讨论】:

  • 我不明白。这不正是我们在stackoverflow.com/a/59904926/341994 中建立的吗?从那以后你倒退了吗?
  • 是的,基本上是这样。当我问这个关于 didFinishLaunching 的问题时,我不知道。我应该关闭其他问题还是在此处链接您?
  • 我不知道 :) 我认为如果这个答案包含指向另一个问题的链接会更容易理解。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-22
  • 2014-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-29
相关资源
最近更新 更多