Skip to content

hweetty/EasyTransitioning

Repository files navigation

EasyTransitioning makes it easier to create seemless transitions when presenting view controllers.

Why?

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.

Example

// 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)

How it works

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 ETFrameActionfor 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).

Further reading

Requirements

  • iOS 7+

Author

Jerry Yu

License

EasyTransitioning is available under the MIT license. See the LICENSE file for more info.

About

Removing the boilerplate code associated with UIViewControllerAnimatedTransitioning

Resources

License

Stars

Watchers

Forks

Packages

No packages published