【问题标题】:Hide switching of storyboards隐藏故事板的切换
【发布时间】:2020-05-19 12:30:34
【问题描述】:

在我的应用程序中,我有 2 个故事板:OnboardingMain。当用户第一次打开应用程序时 - Onboarding 故事板会出现。之后,他按下一个按钮,我向他展示 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)

但那也行不通。

如何通过在过渡期间显示自定义创建的视图来隐藏情节提要的切换? 将不胜感激。

【问题讨论】:

  • 所以你有故事板 1,想在上面展示一个视图,然后用故事板 2 替换该视图下方的故事板 1?
  • @Vollan 正确,然后 - 删除该视图

标签: ios swift uiviewcontroller uistoryboard uipresentingcontroller


【解决方案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 })
    }

}

【讨论】:

  • 我错过了 - self.viiew.layer.zPosition = 1000,将其添加到我的视图后,它就成功了!非常感谢您的帮助!
猜你喜欢
  • 2015-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 1970-01-01
  • 2012-02-07
  • 2017-02-22
  • 1970-01-01
相关资源
最近更新 更多