2024 DesignSwiftUI & UI Frameworks
WWDC24 · 14 min · Design / SwiftUI & UI Frameworks
Enhance your UI animations and transitions
Explore how to adopt the zoom transition in navigation and presentations to increase the sense of continuity in your app, and learn how to animate UIKit views with SwiftUI animations to make it easier to build animations that feel continuous.
Watch at developer.apple.com ↗Chapters
Code shown on screen · 5 snippets
Zoom transition in SwiftUI
NavigationLink {
BraceletEditor(bracelet)
.navigationTransitionStyle(
.zoom(
sourceID: bracelet.id,
in: braceletList
)
)
} label: {
BraceletPreview(bracelet)
}
.matchedTransitionSource(
id: bracelet.id,
in: braceletList
) Zoom transition in UIKit
func showEditor(for bracelet: Bracelet) {
let braceletEditor = BraceletEditor(bracelet)
braceletEditor.preferredTransition = .zoom { context in
let editor = context.zoomedViewController
as! BraceletEditor
return cell(for: editor.bracelet)
}
navigationController?.pushViewController(braceletEditor, animated: true)
} Animate UIView with SwiftUI animation
UIView.animate(.spring(duration: 0.5)) {
bead.center = endOfBracelet
} Animating representables
struct BeadBoxWrapper: UIViewRepresentable {
var isOpen: Bool
func updateUIView(_ box: BeadBox, context: Context) {
context.animate {
box.lid.center.y = isOpen ? -100 : 100
}
}
}
struct BraceletEditor: View {
private var isBeadBoxOpen = false
var body: some View {
BeadBoxWrapper($isBeadBoxOpen.animated())
.onTapGesture {
isBeadBoxOpen.toggle()
}
}
} Gesture-driven animations
switch gesture.state {
case .changed:
UIView.animate(.interactiveSpring) {
bead.center = gesture.translation
}
case .ended:
UIView.animate(.spring) {
bead.center = endOfBracelet
}
} Resources
Related sessions
-
30 min -
23 min