-1

I want to add a transition effect to my app from a ViewController to another.

I want use the transition effect that the Navigation Controller usually add (sliding effect) but without using the Navigation Controller.

What is the simplest and easiest way to achieve that? (I'm using swift 3)

EDIT:

My Code Now:

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad() 
}

@IBAction func GoToMenu(_ sender: UIButton) {
    //TRANSITION EFFECT
    let nextVCID="010101"
    guard let presentedController = self.storyboard?.instantiateViewController(withIdentifier: nextVCID) else { return }

    presentedController.modalTransitionStyle = UIModalTransitionStyle.coverVertical
    self.present(presentedController, animated: true, completion: nil)

}

}
GMX
  • 950
  • 1
  • 14
  • 29

1 Answers1

3

You can present it modaly and set modal transition style you like.

    guard let presentedController = self.storyboard?.instantiateViewController(withIdentifier: nextVCID) else { return }

    presentedController.modalTransitionStyle = UIModalTransitionStyle.coverVertical
    self.present(presentedController, animated: true, completion: nil)
Luzo
  • 1,336
  • 10
  • 15
  • nextVCID: Sorry but where I can find the ID of the ViewController? I have the name of the class but got an error with that. – GMX Dec 17 '16 at 14:39
  • You have to add it to your storyboard to be able to instantiate it from it. Also you have to set this new view controller your class and id. – Luzo Dec 17 '16 at 14:44
  • This is the easiest solution for your needs. You should read up on storyboards and adding a unique identifier to a scene. – Duncan C Dec 17 '16 at 14:46
  • Of course when you do not need IBOutlets and similar stuff, which storyboards offer you, you can always do it like that: `let presentedController = NextViewController()` But you will have to add every button,label, etc. programmatically. – Luzo Dec 17 '16 at 14:55
  • I added the right VCID and I put your code on my button call but when I run the app I see the default transition (From the BOTTOM to the TOP) instead I'd like to have (From Left to Right) as the Navigation Controller usually add. Check my code in the question please – GMX Dec 17 '16 at 15:16
  • 1
    You will have to create your own transition. See http://stackoverflow.com/questions/4541259/iphone-how-to-do-a-presentmodalviewcontroller-animation-from-left-to-right – Luzo Dec 17 '16 at 15:19