Swift - 过渡到 SceneDelegate
Swift -Transition to SceneDelegate
在 iOS 13 之前,我会使用转换从我的 LoginVC 转到我的 TabBarController。我将如何为 SceneDelegate 完成以下操作?此应用只有 1 scene/window
@objc func buttonTapped() {
let transition = CATransition()
transition.duration = 0.4
transition.type = CATransitionType.moveIn
transition.subtype = CATransitionSubtype.fromTop
transition.timingFunction = CAMediaTimingFunction(name:CAMediaTimingFunctionName.default)
let appDelegate = UIApplication.shared.delegate as? AppDelegate
appDelegate?.window?.rootViewController?.view.removeFromSuperview()
appDelegate?.window?.rootViewController?.dismiss(animated: false, completion: nil)
appDelegate?.window?.layer.add(transition, forKey: kCATransition)
appDelegate?.window?.rootViewController = //instance of my TabBarController() and selected index
appDelegate?.window?.isHidden = false
}
@objc func buttonTapped() {
let rootVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Tabbarrrrr") as! Tabbarrrrr
let navigationController = UINavigationController(rootViewController: rootVC)
UIApplication.shared.windows.first?.rootViewController = navigationController
UIApplication.shared.windows.first?.makeKeyAndVisible()
}
您可以使用该代码..
@objc func buttonTapped() {
let transition = CATransition()
transition.duration = 0.4
transition.type = CATransitionType.moveIn
transition.subtype = CATransitionSubtype.fromTop
transition.timingFunction = CAMediaTimingFunction(name:CAMediaTimingFunctionName.default)
if #available(iOS 13, *) {
UIApplication.shared.windows.first?.rootViewController?.view.removeFromSuperview()
UIApplication.shared.windows.first?.rootViewController?.dismiss(animated: false, completion: nil)
UIApplication.shared.windows.first?.layer.add(transition, forKey: kCATransition)
UIApplication.shared.windows.first?.rootViewController = // instance of my TabBarController() and selected index
UIApplication.shared.windows.first?.isHidden = false
} else {
let appDelegate = UIApplication.shared.delegate as? AppDelegate
appDelegate?.window?.rootViewController?.view.removeFromSuperview()
appDelegate?.window?.rootViewController?.dismiss(animated: false, completion: nil)
appDelegate?.window?.layer.add(transition, forKey: kCATransition)
appDelegate?.window?.rootViewController = //instance of my TabBarController() and selected index
appDelegate?.window?.isHidden = false
}
}
在 iOS 13 之前,我会使用转换从我的 LoginVC 转到我的 TabBarController。我将如何为 SceneDelegate 完成以下操作?此应用只有 1 scene/window
@objc func buttonTapped() {
let transition = CATransition()
transition.duration = 0.4
transition.type = CATransitionType.moveIn
transition.subtype = CATransitionSubtype.fromTop
transition.timingFunction = CAMediaTimingFunction(name:CAMediaTimingFunctionName.default)
let appDelegate = UIApplication.shared.delegate as? AppDelegate
appDelegate?.window?.rootViewController?.view.removeFromSuperview()
appDelegate?.window?.rootViewController?.dismiss(animated: false, completion: nil)
appDelegate?.window?.layer.add(transition, forKey: kCATransition)
appDelegate?.window?.rootViewController = //instance of my TabBarController() and selected index
appDelegate?.window?.isHidden = false
}
@objc func buttonTapped() {
let rootVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Tabbarrrrr") as! Tabbarrrrr
let navigationController = UINavigationController(rootViewController: rootVC)
UIApplication.shared.windows.first?.rootViewController = navigationController
UIApplication.shared.windows.first?.makeKeyAndVisible()
}
您可以使用该代码..
@objc func buttonTapped() {
let transition = CATransition()
transition.duration = 0.4
transition.type = CATransitionType.moveIn
transition.subtype = CATransitionSubtype.fromTop
transition.timingFunction = CAMediaTimingFunction(name:CAMediaTimingFunctionName.default)
if #available(iOS 13, *) {
UIApplication.shared.windows.first?.rootViewController?.view.removeFromSuperview()
UIApplication.shared.windows.first?.rootViewController?.dismiss(animated: false, completion: nil)
UIApplication.shared.windows.first?.layer.add(transition, forKey: kCATransition)
UIApplication.shared.windows.first?.rootViewController = // instance of my TabBarController() and selected index
UIApplication.shared.windows.first?.isHidden = false
} else {
let appDelegate = UIApplication.shared.delegate as? AppDelegate
appDelegate?.window?.rootViewController?.view.removeFromSuperview()
appDelegate?.window?.rootViewController?.dismiss(animated: false, completion: nil)
appDelegate?.window?.layer.add(transition, forKey: kCATransition)
appDelegate?.window?.rootViewController = //instance of my TabBarController() and selected index
appDelegate?.window?.isHidden = false
}
}