---
title: "#193: UIView Transition Basics 🐛"
url: https://littlebitesofcocoa.com/193-uiview-transition-basics
author: Jake Marsh
published: 2016-02-17
topics: ["UIKit","Animation"]
description: "Most iOS developers have used the fantastic UIView animateWithDuration family of functions. But there's another, slightly-lesser known static function on..."
---

# #193: UIView Transition Basics 🐛

By Jake Marsh, February 17, 2016. HTML: https://littlebitesofcocoa.com/193-uiview-transition-basics

Most **iOS** developers have used the fantastic **UIView** `animateWithDuration` family of **functions**. But there's another, slightly-lesser known **static function** on **UIView** that can help us <i>transition</i> like a pro. Let's check it out:

The function we'll be trying is `transitionWithView`. At first glance you'll see it's takes the same **duration**, **options**, and **closures** as its more-popular sister **function**.

However, instead of applying our changes over time, this **function** will (<i>conceptually</i>) take a snapshot of our view **before** and **after** the work in the `animations`** closure** is performed, then visually transition from the first snapshot to the second.

``` swift
func flip() {
  flipped = !flipped

  UIView.transitionWithView(
    button,
    duration: 0.3,
    options: .TransitionFlipFromTop,
    animations: {
      self.button.setTitle(self.flipped ? "👎🏻" : "👍🏻", forState: .Normal)
    },
    completion: nil
  )
}
```

The type of transition depends on the animation option we pass in. We can do everything from simple cross-dissolves (fades), to fancy 3D flips. Super handy for simple transitions.

Download a sample project at [j.mp/bite193](http://j.mp/bite193). In it, we flip a thumbs up emoji using this incredibly simple technique.
