在我的应用程序中,我有2个情节提要:Onboarding和Main。用户首次打开应用程序时-出现Onboarding故事板。之后,他按下一个按钮,然后我向他显示Main故事板,其代码如下:
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)
但是那也不行。
如何通过在过渡期间显示自定义创建的视图来隐藏情节提要的切换?非常感谢您的帮助。
只是玩一些它,没有动画或任何特别的东西,但这将为您提供想要的流程:
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 })
}
}