Skip to content

How to develop an animator using system built in animation

Jake Lin edited this page Mar 23, 2016 · 2 revisions

iOS has ~30 built-in transition animations (refer to http://iphonedevwiki.net/index.php/CATransition), we can easily unlock them by create System***Animator in IBAnimatable.

In How to develop an animator (animation controller), we know how to make an animator. To unlock the built-in transition animation, most of steps are already described in the wiki above. There are some difference as below.

  1. The animator's name should start with System like System***Animator, e.g. SystemCubeAnimator and SystemFlipAnimator

  2. Choose the animation in SystemTransitionType to implement.

  3. The implementation of animateTransition is similar to the method animateTransition in SystemCubeAnimator. Replace the SystemTransitionType

public func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
  animateWithCATransition(transitionContext, type: SystemTransitionType.REPLACE_THE_TYPE_HERE, subtype: fromDirection.stringValue)
}
  1. According to my tests, the system built-in transition animations can only support custom Push/Pop transitions. We will see only "Tap to push" button not "Tap to present" button. Feel free to try it in present and let me know if you find something different. To try out present transition for system built-in animations, just comment out presentButton.alpha = 0 (Line 18) in TransitionViewController

  2. Test the animation in the demo app.

  3. No need to create segues since it doesn't support Present/Dismiss transitions.

Example system animators: SystemCubeAnimator and SystemFlipAnimator

That's it. 👏