[英]Transition Animation is not working Swift 5
我正在尝试使用点击手势导航从一个视图控制器导航到另一个视图控制器。 我想在其中添加过渡动画。 我尝试了两种方法,但对我没有用。 -
第一种方法:
UIView.animate(withDuration: 0.5) { ()-> Void in
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let myTabBarController = storyBoard.instantiateViewController(withIdentifier: "profileViewController") as! ProfileViewController
var appDel = UIApplication.shared.delegate as! AppDelegate
appDel.window?.rootViewController = myTabBarController
self.view.layoutIfNeeded()
}
第二种方法:
UIView.animate(withDuration: 0.25,
delay: 0.0,
options: [.curveEaseIn],
animations: {
let controller = self.storyboard!.instantiateViewController(withIdentifier: "mainMenuViewController") as! MainMenuViewController
self.addChild(controller)
self.view.addSubview(controller.view)
controller.didMove(toParent: self)
}, completion: nil)
有人可以告诉我解决方案吗?
试试这个礼物
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "profileViewController") as! ProfileViewController
self.present(nextViewController, animated:true, completion:nil)
如果您提供一个ViewController
那么您只能将其关闭,这可以通过以下代码完成
self.dismiss(animated: true, completion: nil)
推
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "profileViewController") as! ProfileViewController
self.navigationController?.pushViewController(nextViewController, animated:true)
如果按下ViewController
则只能弹出它,可以通过以下代码完成
self.navigationController?.popViewController(animated: true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.