EasyTransitioning makes it easier to create seemless transitions when presenting view controllers.
Users expect applications to be immersive more than ever. Historically this can be accomplished by providing eye candy animations. The next step is to create seemless transitions between different screens to increase continuity of the task.
// 1) Create a `ETTransitionController` instance with strong reference
self.transitionController = ETTransitionController()
// Perform your normal setup
let modalViewController = MyModalViewController()
// 2) Specify the animations that you want to perform
self.transitionController.elements = [
backgroundView.easyTransition(ETFrameAction(toFrame: self.view.bounds, fromFrame: backgroundView.frame)),
titleLabel.easyTransition(ETFrameAction(toFrame: CGRectOffset(titleLabel.frame, 20, 16), fromFrame: titleLabel.frame)),
button.easyTransition(ETFadeAction(toAlpha: 0, fromAlpha: 1)),
otherView.easyTransition(ETCornerRadiusAction(toCornerRadius: 8, fromCornerRadius: 0)),
]
// Optionally specify a custom duration
self.transitionController.animationDuration = 0.42
// 3) Assign this transitioning delegate and present the modal!
modalViewController.transitioningDelegate = self.transitionController
self.presentViewController(modelViewController, animated: true, completion: nil)
There is a lot of boilerplate code assosciated with UIViewControllerAnimatedTransitioning
. This library makes it easier by implementing the required protocols and providing a more expressive way to specify transitions.
A transition is essentially a set of animations between the existing view controller and the presenting modal view controller. Each animation has a from and a to state, similar to the concept of tweening.
ETAction
protocol represents the animation of a single property. There are some bundled actions such as ETCornerRadiusAction
and ETFrameAction
for manipulating the cornerRadius
and frame
attributes respectively. It is also possible to create your own custom action by conforming to this protocol.
There might be multiple attributes comprising of an animation on a single view. ETElement
stores a view and an array of ETAction
's. By default it manipulates a snapshot of the given view instead of it directly. However you can instead create an actual copy of your view if snapshotting should not be used (eg. animating the frame of a aspect-fit UIImageView).
- WWDC 2013 Custom Transitions Using View Controllers
- WWDC 2013 Implementing Engaging UI on iOS
- objc.io View Controller Transitions
- iOS 7+
Jerry Yu
EasyTransitioning is available under the MIT license. See the LICENSE file for more info.