r/iOSProgramming • • Jul 20 '20

Discussion I created a 3D Cube loading animation using SwiftUI

364 Upvotes

31 comments sorted by

30

u/ifelseworks Jul 20 '20

That's neat. Animations do catch my eye

6

u/vijaywargiya Jul 20 '20

Thanks 😊

9

u/[deleted] Jul 20 '20

This might be my favorite thing on this sub 😍

6

u/vijaywargiya Jul 20 '20

Woah, thanks a lot. 😊

2

u/[deleted] Jul 20 '20

Simple brilliant

1

u/vijaywargiya Jul 21 '20

Thanks 😊

2

u/ThePantsThief NSModerator Jul 20 '20

Substack question: is it free for writers? Or is there a paid tier or anything? I love the site, I might write on it

1

u/vijaywargiya Jul 21 '20

It’s completely free unless you start a paid newsletter.

1

u/ThePantsThief NSModerator Jul 21 '20

What about paid articles? (It can do that right?)

1

u/vijaywargiya Jul 21 '20

Yes you can have articles accessed by only your paid subscribers.

2

u/ZennerBlue Jul 20 '20

I’ve spent way too much time of my day today just watching this animation.

Well done, both for the great work, and for making my deliverables late this week :/

1

u/vijaywargiya Jul 21 '20

Haha thanks 😊

2

u/Godmode Jul 21 '20

Very Impressive. Working on a new Swift UI Project and this gave me a good idea to implement something similar. Big Thanks

1

u/vijaywargiya Jul 21 '20

Glad you like it 😊

2

u/[deleted] Jul 21 '20

Looks cool, good job man

1

u/vijaywargiya Jul 21 '20

Thanks 😊

2

u/dark7wizard Jul 21 '20

I always appreciate open source stuff. Thank you my man!

1

u/vijaywargiya Jul 21 '20

Glad you like it 😊

3

u/Kytaliys Jul 20 '20

I love it. What is the reason the cube moving from the front row to the back row has every other cube stopped, whereas when the cubes move within the rows don’t wait for the first cube to finish its animation before the second cube starts moving?

6

u/CleverError Jul 20 '20

There is no space available for any of the other cubes to move into.

https://imgur.com/4ra9TF7

The Yellow and orange cubes are blocked from moving by the blue one.

3

u/BedtimeWithTheBear Jul 21 '20

I think /u/Kytaliys is more referring to the fact that the movement is in groups of 1-2-1-2. For me, it takes away from the smoothness of the animation and makes it look almost like it is stuttering.

It’s not a criticism, merely an observation; I’m convinced I can see Netflix stutter, though I know it doesn’t. I also see that OP was trying to reproduce a specific animation, so I’d say they succeeded.

2

u/vijaywargiya Jul 21 '20

Yep, I was trying to create this animation. https://codemyui.com/lego-style-loading-animation/.

It’s actually simpler to create the one by one animation and I had to add an extra condition to get it how it is now.

1

u/BedtimeWithTheBear Jul 21 '20

Absolutely, I think you did a great job, for what it’s worth.

I imagine getting the one-by-one animation is relatively straightforward, but how complex was it to get the trailing block following with that short delay and the smooth acceleration?

I’ve never done any animation in Swift or any other language, so I’m interested in how you get it working.

2

u/vijaywargiya Jul 21 '20

So to move any block I change it’s x & y co-ordinates. To create one by one animation, we can swap the position with no cube to a cube adjacent to this position. This makes sure that cube moves one by one. There needs to be a delay between such swaps so that the animation can be completed before the next block movement happens. Now to create the trailing animation, we check the position of the block currently being moved. If it’s 1 of the 2 positions where we want the affect we use a shorter delay and everywhere else we use a longer delay. Because of this the next block starts moving before the first block has finished it’s movement. SwiftUI makes sure all this movement happens smoothly.

I also wrote about creating this, so if you are interested you can read it here -

https://thecreativedeveloper.substack.com/p/cube-loading-animation-swiftui

2

u/BedtimeWithTheBear Jul 21 '20

Thank you for the summary. I had a quick skim through your write-up, but I need to find some time to give it the attention it deserves.

2

u/vijaywargiya Jul 20 '20

I was trying to create this animation - https://codemyui.com/lego-style-loading-animation/ and replicated the behaviour from that.