Working with animations in iOS is great, but when you're creating your own it can be time-consuming and tedious. This post shows how using Playgrounds lets you quickly prototype animations while skipping all the project setup.
Before Playgrounds you'd have to re-build your project every time you want to check in on how the animation is coming together. The bigger the project the longer it takes.
Luckily, there is a better way.
Playgrounds are a lightweight interactive coding environment which allow us to experiment and explore Swift and the iOS SDK without the hassle of creating a new Xcode project.
Using Playgrounds you can quickly create and polish animations and get quick visual feedback that you're on the right track. Check out the steps below to get set up and ready to go.
Import XCPlayground by adding
import XCPlayground to the top of the file. This module lets you interact with Xcode from a playground.
Add a container view - this will be your canvas for your animation.
Set your containerView to be the 'live view'
Open the assistant editor
Start building your animation! This is a super-simple example, but you can build much more advanced animations using CoreAnimation and other APIs.
You should see your animation run in the assistant editor:
And that's it - a brilliant way to experiment with and build animations.
You can find the full code here.
To quickly re-run your animation you just need to change something in your playground. Adding a new line to the end of the file will do it.
You can also access it in toolbar
Editor > Execute Playground, or by pressing the play button on the bottom of the playground.
However, my personal favourite is to add a new keyboard shortcut to
Execute Playground. Do this in
Xcode > Preferences > Key Bindings > Search for 'execute'.
We plan, design, and develop the world’s most desirable software products. Our team’s expertise helps brands like Sony, Motorola, Tesco, Channel4, BBC, and News Corp build fully customized Android devices or simply make their mobile experiences the best on the market. Since 2008, our full in-house teams work from London, Liverpool, Berlin, Barcelona, and NYC.
Let’s get in contact