HomeiOS DevelopmentUtilizing SymbolEffect to Animate SF Symbols in SwiftUI

Utilizing SymbolEffect to Animate SF Symbols in SwiftUI


In relation to designing visually interesting and intuitive consumer interfaces in iOS growth, SF Symbols are a useful asset. It gives a complete library of over 5,000 customizable icons, designed particularly for iOS and macOS functions. The most recent iOS 17 replace brings SF Symbols 5, which introduces a incredible assortment of expressive animations. SwiftUI gives builders the power to leverage these animations utilizing the brand new symbolEffect modifier.

This function empowers builders to create numerous and charming animations inside their apps. By incorporating symbolEffect into your SwiftUI code, builders can improve consumer interactions and create visually partaking interfaces. On this tutorial, we are going to present you methods to work with this new modifier to create numerous kinds 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 Coloration, and Exchange. Within the code above, we use the bounce animation. So, whenever you faucet the image within the preview canvas, it reveals a bouncing impact.

symboleffect-demo

Make it Repeatable

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

It will obtain an animated impact that repeats indefinitely. Should you need to repeat the impact for a selected variety of instances, you’ll be able to make the most of the .repeat operate and point out the specified repeat rely as proven under:

Controlling the animation velocity

swiftui-symboleffect-speed

As well as, you may 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 under:

Animation Varieties

As said earlier, SwiftUI offers a wide range of built-in animation varieties, equivalent to Bounce, Scale, Pulse, Variable Coloration, and Exchange. Up till now, we’ve got solely 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 pictures within the preview canvas, you’ll be able to see the animations coming to life. Compared to the bounce animation, the Pulse animation gives a definite impact by step by step 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.

swiftui-symboleffect-animations

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 realize a customized impact by combining completely different animations.

Content material Transition and Exchange Animation

symboleffect-content-transition

In sure eventualities, there could also be a have to transition between completely different symbols inside a picture. As an illustration, when a consumer 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 Exchange animation, as demonstrated under:

Abstract

SF Symbols and symbolEffect present builders with highly effective instruments to boost consumer interactions and create visually partaking interfaces in iOS and macOS functions.

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

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



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments