Monday, May 20, 2024
HomeiOS DevelopmentUtilizing SymbolEffect to Animate SF Symbols in SwiftUI

Utilizing SymbolEffect to Animate SF Symbols in SwiftUI

With regards to designing visually interesting and intuitive person interfaces in iOS improvement, SF Symbols are a useful asset. It affords a complete library of over 5,000 customizable icons, designed particularly for iOS and macOS purposes. The most recent iOS 17 replace brings SF Symbols 5, which introduces a improbable assortment of expressive animations. SwiftUI affords builders the flexibility to leverage these animations utilizing the brand new symbolEffect modifier.

This function empowers builders to create various and charming animations inside their apps. By incorporating symbolEffect into your SwiftUI code, builders can improve person interactions and create visually participating interfaces. On this tutorial, we are going to present you work with this new modifier to create varied sorts of animations.

The Fundamental Utilization of SymbolEffect

To animate a SF image, you’ll be able to connect the brand new symbolEffect modifier to the Picture view and specify the specified animation sort. Right here is an instance:

There are a selection of built-in animations together with Seem, Disappear, Bounce, Scale, Pulse, Variable Colour, and Change. Within the code above, we use the bounce animation. So, once you faucet the image within the preview canvas, it exhibits a bouncing impact.


Make it Repeatable

By default, the animation is simply performed as soon as. To make it repeatable, you’ll be able to set the choices parameter of the modifier to .repeating like this:

This may obtain an animated impact that repeats indefinitely. For those who want to repeat the impact for a selected variety of occasions, you’ll be able to make the most of the .repeat operate and point out the specified repeat depend as proven beneath:

Controlling the animation velocity


As well as, you might have the pliability to customise the animation velocity by using the .velocity operate throughout the choices parameter. As an illustration, for those who want to decelerate the animation, you’ll be able to set the worth of the .velocity operate to 0.1, as demonstrated beneath:

Animation Varieties

As acknowledged earlier, SwiftUI supplies a wide range of built-in animation varieties, comparable to Bounce, Scale, Pulse, Variable Colour, and Change. Up till now, we’ve completely used the bounce animation. Now, let’s discover and take a look at out different animation varieties utilizing the supplied code snippet:

By tapping any of the photographs within the preview canvas, you’ll be able to see the animations coming to life. Compared to the bounce animation, the Pulse animation affords a definite impact by progressively fading the opacity of particular or all layers throughout the picture. Alternatively, the variableColor animation replaces the opacity of variable layers within the picture, offering a novel visible transformation.


Even for the Bounce animation, you’ll be able to specify .bounce.down to bounce the image downward.

For added flexibility, it’s potential to use a number of symbolEffect modifiers to a view, permitting you to attain a customized impact by combining totally different animations.

Content material Transition and Change Animation


In sure situations, there could also be a have to transition between totally different symbols inside a picture. As an illustration, when a person faucets the Contact ID image, it transforms right into a checkmark image. To make sure a seamless and visually pleasing transition, you’ll be able to make the most of the contentTransition modifier along with the Change animation, as demonstrated beneath:


SF Symbols and symbolEffect present builders with highly effective instruments to boost person interactions and create visually participating interfaces in iOS and macOS purposes.

This tutorial demonstrates the essential utilization of symbolEffect, making animations repeatable, controlling animation velocity, and exploring totally different animation varieties. It additionally covers content material transition and change animation.

In case you have discovered this tutorial fulfilling and want to discover SwiftUI additional, we extremely advocate testing our complete e-book, “Mastering SwiftUI.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments