Tejas Ratunawar
Tejas Ratunawar

Reputation: 93

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 ?

Upvotes: 0

Views: 1568

Answers (1)

Vicky_Vignesh
Vicky_Vignesh

Reputation: 592

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

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

self.navigationController?.popViewController(animated: true)

Upvotes: 1

Related Questions