使用UIStoryboardSegue自定义UIViewController的演示过渡
最受欢迎的方式是 UIViewControllerAnimatedTransitioning
为了做到这一点,你必须:
- 新建一个子类,该子类可称为 “XXXTransitioning”,继承自 “NSObject”,并实现协议 “UIViewControllerAnimatedTransitioning “的两个功能。
1 | func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval |
- Then:
- 在 “ViewController “中新建一个 “XXXTransitioning “的实例。
- 设置
transitioningDelegate = self
。 - 用 UIViewControllerTransitioningDelegate 扩展 “ViewController”,并实现。
1 | func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? |
dismiss
我注意到 Storyboard Segue
有一个 Custom
1 | class XXXModalSegue: UIStoryboardSegue { |
就是这样,不用再编码delegate
和Extension
。简单又干净:)