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)
答案 0 :(得分:22)
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)