OnePlus stock boot animation in iOS using CoreAnimation

Vineet
3 min readOct 28, 2020

๐˜ˆ๐˜ฏ๐˜ช๐˜ฎ๐˜ข๐˜ต๐˜ช๐˜ฐ๐˜ฏ๐˜ด ๐˜ข๐˜ณ๐˜ฆ ๐˜ข ๐˜จ๐˜ณ๐˜ฆ๐˜ข๐˜ต ๐˜ธ๐˜ข๐˜บ ๐˜ต๐˜ฐ ๐˜ฅ๐˜ฆ๐˜ญ๐˜ช๐˜จ๐˜ฉ๐˜ต ๐˜ข๐˜ฏ๐˜ฅ ๐˜ฆ๐˜ฏ๐˜จ๐˜ข๐˜จ๐˜ฆ ๐˜ถ๐˜ด๐˜ฆ๐˜ณ๐˜ด. ๐˜ž๐˜ฆ ๐˜ด๐˜ฆ๐˜ฆ ๐˜ฉ๐˜ฐ๐˜ธ ๐˜ฃ๐˜ฆ๐˜ข๐˜ถ๐˜ต๐˜ช๐˜ง๐˜ถ๐˜ญ๐˜ญ๐˜บ ๐˜ช๐˜ต ๐˜ข๐˜ฎ๐˜ฑ๐˜ญ๐˜ช๐˜ง๐˜ช๐˜ฆ๐˜ด ๐˜ต๐˜ฉ๐˜ฆ ๐˜ฐ๐˜ท๐˜ฆ๐˜ณ๐˜ข๐˜ญ๐˜ญ ๐˜œ๐˜Ÿ. ๐˜ˆ๐˜ฏ๐˜ฅ ๐˜ข๐˜ฏ๐˜ช๐˜ฎ๐˜ข๐˜ต๐˜ช๐˜ฐ๐˜ฏ๐˜ด ๐˜ข๐˜ณ๐˜ฆ ๐˜ฑ๐˜ณ๐˜ฆ๐˜ด๐˜ฆ๐˜ฏ๐˜ต ๐˜ข๐˜ญ๐˜ญ ๐˜ฐ๐˜ท๐˜ฆ๐˜ณ ๐˜ณ๐˜ช๐˜จ๐˜ฉ๐˜ต ๐˜ง๐˜ณ๐˜ฐ๐˜ฎ ๐˜ต๐˜ฉ๐˜ฆ ๐˜ฃ๐˜ฐ๐˜ฐ๐˜ต ๐˜ด๐˜ค๐˜ณ๐˜ฆ๐˜ฆ๐˜ฏ ๐˜ฐ๐˜ง ๐˜ข ๐˜ฑ๐˜ฉ๐˜ฐ๐˜ฏ๐˜ฆ ๐˜ต๐˜ฐ ๐˜ต๐˜ฉ๐˜ฆ ๐˜ค๐˜ข๐˜ณ๐˜ฐ๐˜ถ๐˜ด๐˜ฆ๐˜ญ ๐˜ฆ๐˜ง๐˜ง๐˜ฆ๐˜ค๐˜ต ๐˜ช๐˜ฏ ๐˜ข ๐˜ด๐˜ฉ๐˜ฐ๐˜ฑ๐˜ฑ๐˜ช๐˜ฏ๐˜จ ๐˜ข๐˜ฑ๐˜ฑ.

The challenge

I own an OnePlus 3t and was stuck in its beautiful boot animation since a long time. And I thought of giving it a try to achieve it with iOS animations.

Are you ready? Let us get started!

What we will be buildingโ€ฆ

Steps

  1. Draw a square/box view.
Nothing much here

2. Work on the independent components of the box view. Try writing the body of the above functions yourself while using layers. Your output should look like below.

Hint: Go for CAShapeLayer

3. Write the animatePlus function.

innerPlusPath / outerPlusPath functions? ๐Ÿง
  • CATransaction is used for grouping multiple layer-tree operations (in our case animations) into atomic updates to the render tree.
  • We will be using .forwards fillMode and isRemovedOnCompletion in almost every animations to keep the animation in the target layer.
  • Chaining animations with help of a completion block.

4. Hands on the innerPlusPath / outerPlusPath functions.

CGMutablePath to the rescue ๐ŸŽƒ

Output:

๐Ÿคฉ

5. Itโ€™s time to animate the box to a circle with a chain of opacity, transform width and path animations.

Look for redundant code โ˜ ๏ธ
  • CAAnimationGroup allows multiple animations to be grouped and run concurrently.
  • CAMediaTimingFunction defines the pace of an animation as a timing curve.

Output:

๐Ÿ˜

6. Animate the size of the two circles with help of the transfrom property of layer.

7. Now time for the trickiest part of the animation i.e rotation of circles.

Enters CAReplicatorLayer

  • Used CAReplicatorLayer to create a specified number (two instanceCount in our case) of sublayer copies. Provided an instanceDelay to delay the animation of the second sublayer (circle).
  • CAKeyframeAnimation is used to animate the position of the path property.

Output:

So cool!!

7. Next step is to drop the white circle in between the red circle and re form the box once again. Give it a try yourself.

8. Drink a coffee โ˜•๏ธ and enjoy!

Have a look at the full codebase in the below git repo. Do give it a โญ๏ธ if you like it.

I would love to hear from you

You can reach me by the following channel(s):

LinkedIn

Feel free to drop suggestions in the comment section.

Thanks for reading. Happy code documenting!

--

--