0

在我的应用程序中,我有 2 个故事板:OnboardingMain。当用户第一次打开应用程序时 -将显示入职故事板。之后,他按下一个按钮,我向他展示了带有以下代码的Main Storyboard:

let storyboard = UIStoryboard(name: "Shop", bundle: nil)
let navigationVc = storyboard.instantiateViewController(withIdentifier: "ShopScreens") as UIViewController
navigationVc.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.present(navigationVc, animated: false, completion: nil)

当用户切换故事板时,我想制作自定义动画。为此 - 我创建了简单的视图,我在这样的所有内容之上呈现:

UIApplication.shared.keyWindow?.addSubview(self.containerViewForAnimatedView)

此视图运行良好,但仅就一个 Storyboard 而言,它涵盖了应用程序更改屏幕时的所有内容。

但是当我尝试切换故事板时 - 这个视图被新呈现的故事板覆盖。

我还尝试以这种方式呈现视图并将其放在前面:

let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.addSubview(self.containerViewForAnimatedView)

但这也行不通。

如何在过渡期间通过呈现自定义创建的视图来隐藏故事板的切换?将不胜感激任何帮助。

4

1 回答 1

1

只是玩了一些,没有动画或任何特别的东西,但这会给你你想要的流程:

class ViewController: UIViewController {
    let viiew = UIView.init(frame: UIScreen.main.bounds)

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .red

        DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
            self.viiew.backgroundColor = .blue
            UIApplication.shared.keyWindowInConnectedScenes?.resignKey()
            UIApplication.shared.keyWindowInConnectedScenes?.addSubview(self.viiew)
            self.viiew.layer.zPosition = 1000
        }

        DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
            let vc = ViewController2()
            UIApplication.shared.keyWindowInConnectedScenes?.rootViewController = vc
            DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
                self.viiew.removeFromSuperview()
            }
        }
    }


}

class ViewController2: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .green


    }
}

extension UIApplication {

    var keyWindowInConnectedScenes: UIWindow? {
        return windows.first(where: { $0.isKeyWindow })
    }

}
于 2020-02-03T19:47:41.203 回答