Animation in SwiftUI

Eniela P. Vela
Swift Blondie
Published in
2 min readSep 16, 2021

--

Do MORE!

We can build an application in SwiftUI relatively fast but we are not talking about dull and boring application. The most important point on creating an application is not the code behind it. Neither does it mean anything to the user, nor does the user care about it. UX/UI is one of the most important part of the application. Without them, you as a developer will waste time building an application that won’t sell (download).

Animation is one key factor in design part. It brings the elements to live and makes them more interesting. By now, you know that this whole animation, element thingie is converting into SELL (download).

The traditional way of animation is by using the timer. If you are new to SwiftUI, just think of CSS in combination of JavaScript to make the elements fun. In Swift, the theory behind this is that the timer fires every number of seconds that we want, and when this timer fires, we can run the code to update or alter the properties of the elements either the position, the scale, the opacity, or others.

The first thing to start a timer-based animation is to have a timer. In SwiftUI, timers can be a publisher as they publish a steady stream of values as per the duration set on the timer:

let timer = Timer.publish(every: 1, on: .current, in: .common).autoconnect()

--

--

Eniela P. Vela
Swift Blondie

iOS Developer | Technical Writer | Software Developer @ Apple