How to develop an animator using system built in animation
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.
-
The animator's name should start with
System
likeSystem***Animator
, e.g.SystemCubeAnimator
andSystemFlipAnimator
-
Choose the animation in
SystemTransitionType
to implement. -
The implementation of
animateTransition
is similar to the methodanimateTransition
inSystemCubeAnimator
. Replace theSystemTransitionType
public func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
animateWithCATransition(transitionContext, type: SystemTransitionType.REPLACE_THE_TYPE_HERE, subtype: fromDirection.stringValue)
}
-
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) inTransitionViewController
-
Test the animation in the demo app.
-
No need to create segues since it doesn't support Present/Dismiss transitions.
Example system animators: SystemCubeAnimator and SystemFlipAnimator
That's it. 👏