[英]Present ViewController Segue Transition Without Storyboard [Swift]
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). 我对Swift比较陌生,我试图用淡入的方式呈现一个新的View Controller,而不是默认的模态动画(从底部看)。 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. 我尝试使用modalTransitionStyle,但我想我可能没有正确实现它。 Here is my code: 这是我的代码:
var modalStyle: UIModalTransitionStyle = UIModalTransitionStyle.CrossDissolve
StartViewController().modalTransitionStyle = modalStyle
presentViewController(StartViewController(), animated: true, completion: nil)
Each time you call StartViewController()
you are creating a new one. 每次调用StartViewController()
都会创建一个新的。 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: 您可以跳过创建modalStyle
并直接设置modalTransitionStyle
:
let svc = StartViewController()
svc.modalTransitionStyle = .CrossDissolve
presentViewController(svc, animated: true, completion: nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.