交互式Animator:和Animator类似,不过它是交互式的,后面会有详细介绍
Presentation控制器:
它可以对present过程更加彻底的自定义,比如修改被展示视图的大小,新增自定义视图等,后面会有详细介绍。

在这一小节中,我们首先介绍最简单的Animator。回顾一下转场动画必备的6个元素,它们被分为两组,彼此之间没有关联。Animator的作用等同于第二组的四个元素,也就是说对于同一个Animator,可以适用于A跳转B,也可以适用于A跳转C。它表示一种通用的页面跳转时的动画逻辑,不受限于具体的视图控制器。
如果您读懂了这段话,整个自定义的转场动画逻辑就很清楚了,以视图控制器A跳转到B为例:
- 创建动画代理,在事情比较简单时,A自己就可以作为代理
- 设置B的transitioningDelegate为步骤1中创建的代理对象
- 调用presentViewController:animated:completion:并把参数animated设置为true
-
系统会找到代理中提供的Animator,由Animator负责动画逻辑
用具体的例子解释就是:
// 这个类相当于A class CrossDissolveFirstViewController: UIViewController, UIViewControllerTransitioningDelegate { // 这个对象相当于B crossDissolveSecondViewController.transitioningDelegate = self // 点击按钮触发的函数 func animationButtonDidClicked() { self.presentViewController(crossDissolveSecondViewController, animated: true, completion: nil) } // 下面这两个函数定义在UIViewControllerTransitioningDelegate协议中 // 用于为present和dismiss提供animator func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { // 也可以使用CrossDissolveAnimator,动画效果各有不同 // return CrossDissolveAnimator() return HalfWaySpringAnimator() } func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { return CrossDissolveAnimator() } }










