๐๐ฏ๐ช๐ฎ๐ข๐ต๐ช๐ฐ๐ฏ๐ด ๐ข๐ณ๐ฆ ๐ข ๐จ๐ณ๐ฆ๐ข๐ต ๐ธ๐ข๐บ ๐ต๐ฐ ๐ฅ๐ฆ๐ญ๐ช๐จ๐ฉ๐ต ๐ข๐ฏ๐ฅ ๐ฆ๐ฏ๐จ๐ข๐จ๐ฆ ๐ถ๐ด๐ฆ๐ณ๐ด. ๐๐ฆ ๐ด๐ฆ๐ฆ ๐ฉ๐ฐ๐ธ ๐ฃ๐ฆ๐ข๐ถ๐ต๐ช๐ง๐ถ๐ญ๐ญ๐บ ๐ช๐ต ๐ข๐ฎ๐ฑ๐ญ๐ช๐ง๐ช๐ฆ๐ด ๐ต๐ฉ๐ฆ ๐ฐ๐ท๐ฆ๐ณ๐ข๐ญ๐ญ ๐๐. ๐๐ฏ๐ฅ ๐ข๐ฏ๐ช๐ฎ๐ข๐ต๐ช๐ฐ๐ฏ๐ด ๐ข๐ณ๐ฆ ๐ฑ๐ณ๐ฆ๐ด๐ฆ๐ฏ๐ต ๐ข๐ญ๐ญ ๐ฐ๐ท๐ฆ๐ณ ๐ณ๐ช๐จ๐ฉ๐ต ๐ง๐ณ๐ฐ๐ฎ ๐ต๐ฉ๐ฆ ๐ฃ๐ฐ๐ฐ๐ต ๐ด๐ค๐ณ๐ฆ๐ฆ๐ฏ ๐ฐ๐ง ๐ข ๐ฑ๐ฉ๐ฐ๐ฏ๐ฆ ๐ต๐ฐ ๐ต๐ฉ๐ฆ ๐ค๐ข๐ณ๐ฐ๐ถ๐ด๐ฆ๐ญ ๐ฆ๐ง๐ง๐ฆ๐ค๐ต ๐ช๐ฏ ๐ข ๐ด๐ฉ๐ฐ๐ฑ๐ฑ๐ช๐ฏ๐จ ๐ข๐ฑ๐ฑ.
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
- Draw a square/box view.
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.
3. Write the animatePlus function.
- 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.
Output:
5. Itโs time to animate the box to a circle with a chain of opacity, transform width and path animations.
- 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:
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):
Feel free to drop suggestions in the comment section.
Thanks for reading. Happy code documenting!