-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)

}

}
4
  • This is not a duplicate question: I don't want hide a Navigation Controller in all my app for do that! Commented Dec 16, 2016 at 22:05
  • I reopened your question. You are correct, that other question was not a duplicate. Commented Dec 16, 2016 at 22:21
  • Do you want to transition from one view to another or from one view controller to another? Commented Dec 16, 2016 at 22:38
  • From a View Controller to another Commented Dec 17, 2016 at 13:59

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

6 Comments

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.
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.
This is the easiest solution for your needs. You should read up on storyboards and adding a unique identifier to a scene.
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.
You will have to create your own transition. See stackoverflow.com/questions/4541259/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.