Reputation: 9374
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)
Upvotes: 24
Views: 32965
Reputation: 648
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)
Upvotes: 31
Reputation: 3198
For anyone doing this on iOS8, this is what I had to do:
I have a swift class file titled SettingsView.swift and a .xib file named SettingsView.xib. I run this in MasterViewController.swift (or any view controller really to open a second view controller)
@IBAction func openSettings(sender: AnyObject) {
var mySettings: SettingsView = SettingsView(nibName: "SettingsView", bundle: nil) /<--- Notice this "nibName"
var modalStyle: UIModalTransitionStyle = UIModalTransitionStyle.CoverVertical
mySettings.modalTransitionStyle = modalStyle
self.presentViewController(mySettings, animated: true, completion: nil)
}
Upvotes: 15