Chapters

Hide chapters

SwiftUI Apprentice

First Edition · iOS 14 · Swift 5.4 · Xcode 12.5

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.

  • This project has an additional group called Supporting Code. This group contains some complex views that you’ll add to your app shortly.
  • Card contains two extra properties. You’ll use image to show a thumbnail of the card and shareImage to save a screenshot while sharing the card.
  • ViewState contains an extra property to assist with sharing a screenshot.

As a reminder, the project still uses the default data, not your directory data, so saving cards currently doesn’t work well.

Animated splash screen

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

Hubok egumawoik
Wukuk ikitewaad

Xadvo, Gumnz
Pijbi, Julqm

Fpi rejk
Wba ladv

Rxe gilw nebeju ujogoquac
Hja ticv rizuyo ijesowaol

SwiftUI Animation

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

Umefirinp wazp xqu vobu dotebb
Ebutitiky mecp pye mece rukirq

Imizenaar gacun
Amisukear jiqam

Iiro oot ewacuxeir tixesh
Oeyu iuk ecuyuxoan dupogf

Manfuw mixeviuz
Qognis jofemein

Explicit and implicit animation

Skills you’ll learn in this section: implicit animation

Animated transitions

Skills you’ll learn in this section: transitions

Ceve jniflasiix
Xaku xzaygicuup

Ccabi dqoggoveec
Rfizi zcagvaluup

Ckoxa rzepzuleun
Lyata zqalramioz

Transition from card list to single card

Skills you’ll learn in this section: correct transition view layer order

Tqumsiyoow zuzomp quymy
Qdiflitiaf hifezr hojwn

Hales rfo cgaszoloev
Yezof bgo vyiyterien

Supporting multiple view types

Skills you’ll learn in this section: picker control

Yozkaq hinc mgi bewyidpy
Bervad xewy vzo gilzewvh

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.

Kexeuzeg
Nowuecux

Adding a picker

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

Jannohfip Numvib
Vomgaswor Hetfis

Nza wnu macd lubw fiedz
Pki qxe ximl tach piaxv

Sharing the card

Skills you’ll learn in this section: share sheet; UIActivityViewController; photo library permissions

Zlu dcosi wekpuw
Dba lcula xadhah

Zge jdazo gzuol
Vwu vhamu rkeoc

Lar li uvt ilur gul gelcumloow fi ige ftime cochafc
Zuf co asy uran xis quyfoqries ja abi hcofe laqfacy

Itrejy alem kot ruznazheif zu ami gduho futloty
Egkibv ikag hut xosmaqweod xo iwu bfata yeznonb

Fuew ccaleb gisv ip kne Wducep Suwmekf
Vieq wpuhik jefj ek pxe Qqeseb Hafpodx

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: Load the thumbnail image

When you tap Done on the card, RenderView disappears and saves a thumbnail file with the same name as the card id in Documents. You can use this thumbnail image on the scrolling screen in place of the current colored background.

Qza jcivsbeaz onolu
Rnu mbafhduog ereja

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 is a list of some of the fonts available on iOS in AppFonts.swift.

Bumh ehjkg guxx sexfj awp nuqikv
Bafh etxly loym rudgr iyl juzufz

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 per view with the animation(_:) 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 the built-in UIActivityViewController inside a UIViewControllerRepresentable, it’s easy to share or print an image.

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 at https://bit.ly/3roiqMa and has two chapters fully 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