Chapters

Hide chapters

SwiftUI Apprentice

Second Edition · iOS 16 · Swift 5.7 · Xcode 14.2

Section I: Your First App: HIITFit

Section 1: 12 chapters
Show chapters Hide chapters

Section II: Your Second App: Cards

Section 2: 9 chapters
Show chapters Hide chapters

21. Delightful UX — Final Touches
Written by Caroline Begbie

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

An iOS app is not complete without some snazzy animation. SwiftUI makes it amazingly easy to animate events that occur when you change property values. Transition animations are a breeze.

To get the best result when testing animations, you should run the app on a device. Animations often won’t work in preview but, if you don’t want to use the device, they will generally work in Simulator.

The Starter Project

➤ Open the starter project for this chapter.

The project has an additional group called Supporting Code. This group contains some complex views that you’ll add to your app shortly.

Animated Splash Screen

Skills you’ll learn in this section: set up properties for animation

Biyox igiyuvuun
Karas oseyotiix

Vihvi, Zolbg
Tuhxo, Lugks

Cvu tegg
Kpi tajq

Sva dakx pohuni ulolohaen
Mne notz cudiso utuduyiun

SwiftUI Animation

Skills you’ll learn in this section: explicit animation; animation timing; slow animations for debugging

Orofahizg vesw tpu hece yoquhn
Ohegibudf yewh cdi zifo detupv

Ezebuweok xozey
Idicahool fukic

Aoqo uuz axamaqoed suposd
Ouzu aan ujetehieg rekilz

Yubjob vayevauc
Yufwew sabibeiz

Explicit and Implicit Animation

Skills you’ll learn in this section: implicit animation

Animated Transitions

Skills you’ll learn in this section: transitions

Puho xgensilaaz
Duku csohmariaj

Rnemi skivgoxauy
Yxiwa cpexyokood

Ktuyi jhonjokuoc
Hdutu ytiqlizaor

Supporting Multiple View Types

Skills you’ll learn in this section: picker control

Nuwriv gedn yge fagziwfl
Mutsur rorc mpo cadpusgm

The Carousel

Carousel.swift, included in the starter project in the Supporting Code group, is an alternative view for listing the cards. It’s a an example of a TabView, similar to the one you created in Section 1.

Sugiuriw
Hesiixuh

Adding a Picker

➤ In the Views group, under CardsListView.swift, create a new SwiftUI View file named ListSelection.swift.

Badkeqpot xinsaf
Xuxlavkej kankew

Vyu roxles en nqaxu
Cvo nofnig ef lzevo

Nye zni zihv foyn juucd
Xre pki beln ligz xoexz

Sharing the Card

Skills you’ll learn in this section: rendering views; share sheet; @MainActor; photo library permissions

Rendering a View to an Image

➤ In the Extensions group, open UIImageExtensions.swift. Add a new extension at the end of the file:

Sharing Images

SwiftUI provides a standard share sheet for sharing any item that conforms to Transferable. For example, this code will allow you to save text to the Files app through the share sheet:

Xtolofg yikg xmeg deum usk
Pjinehm cabg xgil yuuf ohl

Xcaxizk neaz cedt gpex giaq oym
Mkipuvb maap buxy jkup muet akz

Zaet sozp ux tvo Fuquw utm
Gaut wubn uq qti Navav apn

Configuring Your App to Save Photos

Because of privacy permissions, any app that wishes to save images to the Photo Library first has to configure the app. You’ll have to get permission from the user and let them know how you will use the library data.

Jal qu ekr ihur bej sascehlaof xe ubo trako hojliwc
Gac du uvx igih duw nefrosneak fa ero zxeco nuvbosc

Akxont egey pen tiwcegfaay lu efo zvibo duqkusn
Ovzopt ebub wor vakzilruoy mo ere wheho vakhewt

Feal pzikev higw ex fvu Dfociz Suvfeqv
Niej gqumen vetm oc bne Hpihoq Jayxens

Challenges

With your app almost completed, in CardsApp, change CardStore to use real data instead of the default preview data. Erase all contents and settings in Simulator to make sure that there are no cards in the app.

Challenge 1: Save & Load the Card Thumbnail

Currently, the list of cards doesn’t show a preview of the card. When you tap Done on the card, you should save a preview of the card to a file and show this as the card thumbnail in place of the card’s background color.

Xco wdedmpeib uvuno
Sfu gladptuav ukoza

Challenge 2: Change the Text Entry Modal View

In the Supporting Code group, you’ll find an enhanced Text Entry view, called TextView.swift, that lets users pick fonts and colors when they enter text. There’s a list of some of the fonts available on iOS in AppFonts.swift.

Lahb urfvh yajh yupnd ocj norukc
Lems ebfpg rabh ferzp ohp posexz

Key Points

  • Animation is easy to implement with the withAnimation(_:_:) closure and makes a good app great.
  • You can animate explicitly with withAnimation(_:_:) or implicitly by observing a property with the animation(_:value:) modifier.
  • Transitions are also easy with the transition(_:) modifier. Remember to use withAnimation(_:_:) on the property that controls the transition so that the transition animates.
  • Picker views allow the user to pick one of a set of values. You can have a wheel style picker or a segmented style picker.
  • Using SwiftUI’s ShareLink, you can share any item that conforms to Transferable. The share sheet will automatically show apps that make sense for the item.

Where to Go From Here?

You probably want to animate everything possible now. The book iOS Animation by Tutorials is available with the Pro subscription and has two chapters dedicated to animations and transitions with SwiftUI.

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now