简体   繁体   English

过渡动画不起作用Swift 5

[英]Transition Animation is not working Swift 5

I am trying to navigate from one view controller to other using tap gesture navigation. 我正在尝试使用点击手势导航从一个视图控制器导航到另一个视图控制器。 I want add transition animation into it. 我想在其中添加过渡动画。 I tried with two ways but it didn't worked for me. 我尝试了两种方法,但对我没有用。 - -

First approach : 第一种方法:

               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()
                }

Second approach : 第二种方法:

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)

Can anybody please tell me whats the solution ? 有人可以告诉我解决方案吗?

try this to present 试试这个礼物

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "profileViewController") as! ProfileViewController
self.present(nextViewController, animated:true, completion:nil)

If you present a ViewController then you can only Dismiss it, It can be done by below code 如果您提供一个ViewController那么您只能将其关闭,这可以通过以下代码完成

self.dismiss(animated: true, completion: nil)

To push

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "profileViewController") as! ProfileViewController
self.navigationController?.pushViewController(nextViewController, animated:true)

If you push a ViewController then you can only Pop it, It can be done by below code 如果按下ViewController则只能弹出它,可以通过以下代码完成

self.navigationController?.popViewController(animated: true)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM