Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Present ViewController Segue Transition Without Storyboard [Swift]

Tags:

ios

swift

iphone

I'm relatively new to Swift and I'm trying to present a new View Controller with a fade-in as opposed to the default modal animation (appear from bottom). I am not using storyboards and I wanted to see if there's a good way to do this programmatically. I tried using modalTransitionStyle but I think I may not have implemented it properly. Here is my code:

    var modalStyle: UIModalTransitionStyle = UIModalTransitionStyle.CrossDissolve
    StartViewController().modalTransitionStyle = modalStyle
    presentViewController(StartViewController(), animated: true, completion: nil)
like image 449
user2155400 Avatar asked May 24 '15 21:05

user2155400


People also ask

How do I remove a view controller from storyboard?

To delete the View Controller from the storyboard, select the View Controller by clicking the Show Document Outline icon and then clicking on View Controller Scene in the Document Outline. Then press Backspace or choose Edit > Delete.


1 Answers

Each time you call StartViewController() you are creating a new one. Instead, put that into a constant so that you can refer to the same one:

let modalStyle = UIModalTransitionStyle.CrossDissolve
let svc = StartViewController()
svc.modalTransitionStyle = modalStyle
presentViewController(svc, animated: true, completion: nil)

You can skip creating modalStyle and just set the modalTransitionStyle directly:

let svc = StartViewController()
svc.modalTransitionStyle = .CrossDissolve
presentViewController(svc, animated: true, completion: nil)
like image 186
vacawama Avatar answered Oct 19 '22 08:10

vacawama