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)
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With