How to change presentViewController Transition animation

Stranger B. picture Stranger B. · Aug 17, 2015 · Viewed 25.6k times · Source

I'm using presentViewController to change from a view to another without Navigation Controller like:

let HomeView = self.storyboard!.instantiateViewControllerWithIdentifier("HomeView") as! ViewControllerHome
self.presentViewController(HomeView, animated:true, completion: nil)

How to change the transition? I want to the same animation like the Navigation controller.

I can use another transitions, but I don't find the transition I want here is the code I'm using

let HomeView = self.storyboard!.instantiateViewControllerWithIdentifier("HomeView") as! ViewControllerHome
HomeView.modalTransitionStyle = UIModalTransitionStyle.PartialCurl
self.presentViewController(HomeView, animated:true, completion: nil)

Answer

Mar-k picture Mar-k · Oct 11, 2016

The answer of Mehul is correct but you can also do it the way you want it. With the instantiateViewController(withIndentifier: string)

This is how I do it:

let destController = self.storyboard?.instantiateViewController(withIdentifier: "") as! YourViewController
destController.modalTransitionStyle = .flipHorizontal
self.navigationController?.present(destController, animated: true, completion: nil)  // OR

let destController = self.storyboard?.instantiateViewController(withIdentifier: "") as! YourViewController
destController.modalTransitionStyle = .flipHorizontal
self.present(destController, animated: true, completion: nil)