Bees & Bombs
Rebuilding a gif from Bees & Bombs
In this tutorial we’re going to reconstruct a lovely gif posted by Bees & Bombs. The specific gif is one they posted on twitter, which is slightly different (only in color) from their dribble post.
Here’s what we’ll be building:
Let’s get to it.
Visually, there are 4 circles, each with a cut-out that rotates (sometimes in sync with the circle, sometimes not). This seems like it would be pretty tough to recreate, what with the changing shape of the cutouts.
However, to recreate this we only need to simulate the cut outs. If we think about the shapes in terms of stacked layers, the animation ends up being pretty straight forward.
To achieve the visual effect of the gif we’re going to use (instead of 4 circles) the following layers:
10 things not 4!
Here’s a snapshot of the layers as seen from Xcode:
We can do this step in one shot. What we’ll do is:
Your setup will look like this:
Hit Run.
This is what your sketch should now look like! Pretty spot-on, right?
Now, if you comment out the lines that style the wedges, you’ll see that they look like this:
The animation also has a component where all “the cutouts” move in unison. We’re going to handle this by adding a white view over top of everything so it will look like the wedges are moving together.
Add the following to the end of your
setup
method
That’s it. There’s a white square on top of where the wedges already make it look like a white square.
Note: we turned the visibility of the square off for now.
When I first tried making the animations it seemed like I could do repeats = true
and reverses = true
on them. However, I realized that there’s actually a little bit of a gap between rotations, so I found it better to break the rotations into 2 animations that call one another continuously.
Before we continue, add the following constant to your setup
method:
The two animations are broken up into forward (clockwise) and backward (counterclockwise).
The basic steps are:
These steps are applied for both directions.
The forward animation looks like this:
Add the following to
setup
:
The backward rotation looks like this.
Add the following to
setup
:
To create the cycling animation, we’re going to call the forward and backward animations from one another’s completion observers. We’re also going to handle the behaviour of the large square animation by toggling the visibility of the wedges and mainSquare
.
After a forwards rotation we can reveal mainSquare
so that it’s ready to spin. We also hide the wedges before initiating containerRotateBackward
.
Add the following to
setup
:
The exact opposite of the previous completion, toggles the visibility of the wedges and mainSquare
in preparation for the forward animation.
Add the following to
setup
:
We’re just about done.
Add the following to the end of
setup
:
Hit Run!
That’s it. We broke down what looked like a complex animation of 4 shapes into a process of animating 6 layers (i.e. 5 shapes, a container and a main square), while toggling 5 separate layers (i.e. the wedges and the main square).
For a complete copy of the code, see this gist: Bees + Bombs
And, if you want to see how this could be done with masks: Bees + Bombs w/ Masks