24

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)
Forge
  • 6,538
  • 6
  • 44
  • 64
Stranger B.
  • 9,004
  • 21
  • 71
  • 108
  • Its been answered here very well, pretty old question though. : http://stackoverflow.com/questions/5004102/is-there-a-way-to-change-the-animation-style-of-a-modal-view-controller-appearan – lazyDroid Aug 17 '15 at 10:05
  • @lazyDroid thanks, I managed to make the code added to the post, I can change the animation but I don't find the animation I want – Stranger B. Aug 17 '15 at 10:29
  • Use a navigation controller. You can remove all the stuff you don't want and get the animation. – GaétanZ Aug 17 '15 at 10:51
  • Try using https://github.com/MengTo/Spring it's easy to implement and has extra animations. – AMAN77 Aug 25 '16 at 13:02

2 Answers2

31

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)  
Mar-k
  • 648
  • 6
  • 16
15

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)
    }
Forge
  • 6,538
  • 6
  • 44
  • 64
Mehul
  • 3,033
  • 23
  • 37
  • 1
    This collection of animations provided by Apple is ridiculous. It provides overwhelming and barely practical things like PartialCurl, but miss basic things like CoverHorizontal. – Martin Braun Jan 10 '18 at 16:16