Member-only story
Custom UIViewController Animations — EASY iOS Guide
A nice little guide for you
Difficulty: Beginner | Easy | Normal | Challenging
If you want to have custom transitions between your view controllers, this is the article for you! Equally the repo might help you out. The end result of the tutorial is this fading sceen:
Prerequisites:
* You will need to be familar with the basics of Swift and able to start a Playground (or similar)
* You can follow along with how to create segues here:
Terminology:
Transition animation: The animation that is displayed while a ViewController is displayed with PUSH
, POP
or other transitions
The theory
Transitioning Delegate:
We start an animation (which is often triggered with a segue
. When you present or dismiss a UIViewController
, UIKit
asks the transitioning delegate UIViewControllerTransitioningDelegate
for the animation controller to use.
Animation Controller:
UIViewControllerAnimatedTransitioning
is returned from the UIViewControllerTransitioningDelegate
from the public func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning?
function.
The steps
* A transaction is triggered, typically be a transition
* UIKit
asks the segue
for the transitioning delegate
* The transitioning delegate uses public func animationController(forPresented presented: , presenting: , source: ) -> UIViewControllerAnimatedTransitioning?
for the animation
* UIKit
constructs the transitioning context
* UIKit
uses animateTransition(using:)
to perform the animation
* The animation constroller calls completeTransition(_:)