---
title: "#233: Gesture-Driven Animations with Interpolate 🚶🏼🏃🏼"
url: https://littlebitesofcocoa.com/233-gesture-driven-animations-with-interpolate
author: Jake Marsh
published: 2016-05-04
topics: ["Libraries","Animation"]
description: "Animation plays a key role in how we understand the user interfaces in the software we use. This role expands itself when animations are driven directly..."
---

# #233: Gesture-Driven Animations with Interpolate 🚶🏼🏃🏼

By Jake Marsh, May 4, 2016. HTML: https://littlebitesofcocoa.com/233-gesture-driven-animations-with-interpolate

<img src="https://camo.githubusercontent.com/0f1c876398ca21b55babe0df926baf52d3498d5f/687474703a2f2f692e67697068792e636f6d2f323646786f6c4c7a334152316f7a3631792e676966" style="float: right; margin-left: 20px; margin-bottom: 20px; max-width: 300px;"/>

_Animation_ plays a key role in how we understand the user interfaces in the software we use. This role expands itself when animations are driven directly from a user's gestures or interactions with the interface. Today we'll look at a new framework that can help us create these types of experiences without breaking a sweat. Let's dive in.

It's called [Interpolate](https://github.com/marmelroy/Interpolate) and it's by [Roy Marmelstein](https://github.com/marmelroy).

As the project's **README** puts it: <i>"all animation is the interpolation of values over time."</i>

[Interpolate](https://github.com/marmelroy/Interpolate) helps us describe <i>the relationships that we want to exist</i> between a user's gesture and the interpolated values that should result for the properties of our views. Let's try it by animating a color.

``` swift
let colorChange = Interpolate(
  from: UIColor.whiteColor(),
  to: UIColor.redColor(),
  apply: { [weak self] (result) in
    if let color = result as? UIColor {
      self?.view.backgroundColor = color
    }
  }
)
```

The _Interpolate_ type holds some configuration, next we'll want to wire it up to a gesture:

``` swift
func handlePan(recognizer: UIPanGestureRecognizer) {
  let translation = recognizer.translationInView(self.view)
  let translatedCenterY = view.center.y + translation.y
  let progress = translatedCenterY / self.view.bounds.size.height

  colorChange.progress = progress
}
```

Since **Pan GRs** report every step of their progress as a simple float (from 0.0 - 1.0), we can simply set that progress percentage value directly on the **Interpolate** object.

There's tons more too, [Interpolate](https://github.com/marmelroy/Interpolate) supports easing **functions**, and works on all sorts of foundation types (**points**, **rects**, **colors**, etc.). 

More info about _Interpolate_ can be found at [git.io/interpolate](http://git.io/interpolate)
