如何在主屏幕之前显示登录屏幕?

问题描述 投票:0回答:1

我正在 Xcode 中使用 Swift 制作一个 iOS 应用程序。我有启动屏幕,加载后会转到主故事板。我已经制作了一个注册/登录页面,并希望它出现在启动屏幕之后。查了一下,目前还没有找到任何东西。任何帮助将不胜感激。

顺序为:启动屏幕 - 登录 - 主屏幕

我看过不同的方法,但没有看到看起来像我想要的方法

ios swift storyboard
1个回答
0
投票

你可以像这样制作 Deeplink 以及 rootViewController 到特定的 ViewController

static func decideAndMakeRoot(displayVc: UIViewController,nextVc:UIViewController? = nil) {
    DispatchQueue.main.async {
        let nvc = UINavigationController(rootViewController: displayVc)
        Helper.getInstance.makeSpecificViewRoot(vc: nvc)
        if let nextVc {
            DispatchQueue.main.asyncAfter(deadline: .now()+1) {
                nvc.pushViewController(nextVc, animated: true)
            }
        }
    }
}

///set specific view controller as root
public func makeSpecificViewRoot(vc: UIViewController){
    var snapshot: UIView?
    var rootVC: UIViewController?
    rootVC = vc
    DispatchQueue.main.async {
        snapshot = (UIApplication.shared.windows.first(where: \.isKeyWindow)?.snapshotView(afterScreenUpdates: true))
        if let snapshot, let rootVC {
            rootVC.view.addSubview(snapshot);
            UIApplication.shared.windows.first(where: \.isKeyWindow)?.rootViewController = rootVC;
            UIView.transition(with: snapshot, duration: 0.4, options: .transitionCrossDissolve, animations: {
                snapshot.layer.opacity = 0;
            }, completion: { (status) in
                snapshot.removeFromSuperview()
            })
        } else {
            print("🔥 No snapshot found")
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.