Token导航 LogoToken导航

Agent Skill · 前端设计

axiom-swiftui-animation-ref(Axiom Swiftui 动画参考)

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。它适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段;涉及页面改动时,应配合本地预览和构建检查确认视觉效果。

axiom-swiftui-animation-ref 是前端设计类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为只读;许可证为 MIT,第三方扫描已通过,按安装量在前端设计类的 10,216 个 Skill 里排第 1,539。

总安装 5,061周安装 213GitHub Stars 873下载 1,772核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
MIT

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:axiom-swiftui-animation-ref(Axiom Swiftui 动画参考)
来源仓库:https://github.com/charleswiltgen/axiom
仓库路径:skills/axiom-swiftui-animation-ref
安装命令:
npx skills add https://github.com/charleswiltgen/axiom --skill axiom-swiftui-animation-ref
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/charleswiltgen/axiom --skill axiom-swiftui-animation-ref

这个 Skill 是做什么的

前端设计类 Skill 关注页面结构、视觉规范和组件写法,输出通常是可运行的界面代码。

用于 SwiftUI 动画系统参考,包含 Animatable 协议和 @Animatable 宏。适用于数学插值原理、Transaction 系统和相位动画配置。提供 spring、easeInOut 等动画类型和时间曲线定制方法。安装前建议确认权限范围和维护状态,避免触发联网或文件读写操作。

axiom-swiftui-animation-ref 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/axiom-swiftui-animation-ref

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/charleswiltgen/axiom --skill axiom-swiftui-ani…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它标注为只读,先用只读任务试一次,确认行为符合预期再扩大使用范围。

常见问题

6 条

axiom-swiftui-animation-ref 怎么安装?

在终端执行 npx skills add https://github.com/charleswiltgen/axiom --skill axiom-swiftui-animation-ref。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

axiom-swiftui-animation-ref 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

axiom-swiftui-animation-ref 需要什么权限?

权限级别是只读。该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

axiom-swiftui-animation-ref 是免费的吗?

来源标注的许可证是 MIT。本站不代收任何费用,也不托管安装包;能否商用、要不要署名,以许可证原文为准。

axiom-swiftui-animation-ref 用的人多吗?

公开数据是累计安装 5,061 次,近一周安装 213 次,下载 1,772 次,GitHub 873 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

axiom-swiftui-animation-ref 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 3 个目录同时收录,说明这个 Skill 流传比较广。
  • 许可证明确为 MIT,商用和分发边界好判断。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理前端设计类任务、又不想每次都手写提示词的人。
  • 需要许可证清楚、并且有第三方扫描结果的团队项目。

不太适合

  • 需要厂商级技术支持和 SLA 的生产系统。

前端设计类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
frontend-design

前端设计 · Codex、Claude

8,823,360126,072只读MIT通过
vercel-composition-patterns

Vercel 组合模式 · Codex、Claude

3,858,81625,893需要联网MIT通过
vercel-react-native-skills

Vercel React native skills 前端 · Codex、Claude

2,468,66425,878只读MIT通过
adapt

adapt 搜索 · Codex、Claude

2,027,04023,125操作浏览器未明确通过
bolder

bolder 分析 · Codex、Claude

2,004,28823,130只读未明确通过
axiom-swiftui-animation-ref

Axiom Swiftui 动画参考 · 本页

5,061873只读MIT通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

SwiftUI Animation

Overview

Comprehensive guide to SwiftUI's animation system, from foundational concepts to advanced techniques. This skill covers the Animatable protocol, the iOS 26 @Animatable macro, animation types, and the Transaction system.

Core principle Animation in SwiftUI is mathematical interpolation over time, powered by the VectorArithmetic protocol. Understanding this foundation unlocks the full power of SwiftUI's declarative animation system.

System Requirements

  • iOS 13+: Animatable protocol, timing/spring animations
  • iOS 17+: Default spring animations, scoped animations, PhaseAnimator, KeyframeAnimator
  • iOS 18+: Zoom transitions, UIKit/AppKit animation bridging
  • iOS 26+: @Animatable macro

Part 1: Understanding Animation

What Is Interpolation

Animation is the process of generating intermediate values between a start and end state.

Example: Opacity animation
.opacity(0) → .opacity(1)

While this animation runs, SwiftUI computes intermediate values:

0.0 → 0.02 → 0.05 → 0.1 → 0.25 → 0.4 → 0.6 → 0.8 → 1.0

How values are distributed

  • Determined by the animation's timing curve or velocity function
  • Spring animations use physics simulation
  • Timing curves use bezier curves
  • Each animation type calculates values differently

VectorArithmetic Protocol

SwiftUI requires animated data to conform to VectorArithmetic — providing subtraction, scaling, addition, and a zero value. This enables SwiftUI to interpolate between any two values.

Built-in conforming types: CGFloat, Double, Float, Angle (1D), CGPoint, CGSize (2D), CGRect (4D).

Key insight Vector arithmetic abstracts over dimensionality. SwiftUI animates all these types with a single generic implementation.

Why Int Can't Be Animated

Int doesn't conform to VectorArithmetic — no fractional intermediates exist between 3 and 4. SwiftUI simply snaps the value.

Solution: Use Float/Double and display as Int:

@State private var count: Float = 0
// ...
Text("\(Int(count))")
    .animation(.spring, value: count)

Model vs Presentation Values

Animatable attributes conceptually have two values:

Model Value
  • The target value set by your code
  • Updated immediately when state changes
  • What you write in your view's body
Presentation Value
  • The current interpolated value being rendered
  • Updates frame-by-frame during animation
  • What the user actually sees

Example

.scaleEffect(selected ? 1.5 : 1.0)

When selected becomes true:

  • Model value: Immediately becomes 1.5
  • Presentation value: Interpolates 1.0 → 1.1 → 1.2 → 1.3 → 1.4 → 1.5 over time

Part 2: Animatable Protocol

Overview

The Animatable protocol allows views to animate their properties by defining which data should be interpolated.

protocol Animatable {
    associatedtype AnimatableData: VectorArithmetic

    var animatableData: AnimatableData { get set }
}

SwiftUI builds an animatable attribute for any view conforming to this protocol.

Built-in Animatable Views

Many SwiftUI modifiers conform to Animatable:

Visual Effects
  • .scaleEffect() — Animates scale transform
  • .rotationEffect() — Animates rotation
  • .offset() — Animates position offset
  • .opacity() — Animates transparency
  • .blur() — Animates blur radius
  • .shadow() — Animates shadow properties
All Shape types
  • Circle, Rectangle, RoundedRectangle
  • Capsule, Ellipse, Path
  • Custom Shape implementations

AnimatablePair for Multi-Dimensional Data

When animating multiple properties, use AnimatablePair to combine vectors. For example, scaleEffect combines CGSize (2D) and UnitPoint (2D) into a 4D vector via AnimatablePair<CGSize.AnimatableData, UnitPoint.AnimatableData>. Access components via .first and .second. The @Animatable macro (iOS 26+) eliminates this boilerplate entirely.

Custom Animatable Conformance

When to use
  • Animating custom layout (like RadialLayout)
  • Animating custom drawing code
  • Animating properties that affect shape paths
Example: Animated number view
struct AnimatableNumberView: View, Animatable {
    var number: Double

    var animatableData: Double {
        get { number }
        set { number = newValue }
    }

    var body: some View {
        Text("\(Int(number))")
            .font(.largeTitle)
    }
}

// Usage
AnimatableNumberView(number: value)
    .animation(.spring, value: value)

How it works

  1. number changes from 0 to 100
  2. SwiftUI calls body for every frame of the animation
  3. Each frame gets a new number value: 0 → 5 → 15 → 30 → 55 → 80 → 100
  4. Text updates to show the interpolated integer

Performance Warning

Custom Animatable conformance is expensive — SwiftUI calls body for every frame on the main thread. Built-in effects (.scaleEffect(), .opacity()) run off-main-thread and don't call body. Use custom conformance only when built-in modifiers can't achieve the effect (e.g., animating a custom Layout that repositions subviews per-frame).


Part 3: @Animatable Macro (iOS 26+)

Overview

The @Animatable macro eliminates the boilerplate of manually conforming to the Animatable protocol.

Before iOS 26, you had to:

  1. Manually conform to Animatable
  2. Write animatableData getter and setter
  3. Use AnimatablePair for multiple properties
  4. Exclude non-animatable properties manually

iOS 26+, you just add @Animatable:

@MainActor
@Animatable
struct MyView: View {
    var scale: CGFloat
    var opacity: Double

    var body: some View {
        // ...
    }
}

The macro automatically:

  • Generates Animatable conformance
  • Inspects all stored properties
  • Creates animatableData from VectorArithmetic-conforming properties
  • Handles multi-dimensional data with AnimatablePair

Before/After Comparison

Before @Animatable macro
struct HikingRouteShape: Shape {
    var startPoint: CGPoint
    var endPoint: CGPoint
    var elevation: Double
    var drawingDirection: Bool // Don't want to animate this

    // Tedious manual animatableData declaration
    var animatableData: AnimatablePair<AnimatablePair<CGFloat, CGFloat>,
                        AnimatablePair<Double, AnimatablePair<CGFloat, CGFloat>>> {
        get {
            AnimatablePair(
                AnimatablePair(startPoint.x, startPoint.y),
                AnimatablePair(elevation, AnimatablePair(endPoint.x, endPoint.y))
            )
        }
        set {
            startPoint = CGPoint(x: newValue.first.first, y: newValue.first.second)
            elevation = newValue.second.first
            endPoint = CGPoint(x: newValue.second.second.first, y: newValue.second.second.second)
        }
    }

    func path(in rect: CGRect) -> Path {
        // Drawing code
    }
}
After @Animatable macro
@Animatable
struct HikingRouteShape: Shape {
    var startPoint: CGPoint
    var endPoint: CGPoint
    var elevation: Double

    @AnimatableIgnored
    var drawingDirection: Bool // Excluded from animation

    func path(in rect: CGRect) -> Path {
        // Drawing code
    }
}

Lines of code: 20 → 12 (40% reduction)

@AnimatableIgnored

Use @AnimatableIgnored to exclude properties from animation.

When to use
  • Debug values — Flags for development only
  • IDs — Identifiers that shouldn't animate
  • Timestamps — When the view was created/updated
  • Internal state — Non-visual bookkeeping
  • Non-VectorArithmetic types — Colors, strings, booleans
Example
@MainActor
@Animatable
struct ProgressView: View {
    var progress: Double // Animated
    var totalItems: Int // Animated (if Float, not if Int)

    @AnimatableIgnored
    var title: String // Not animated

    @AnimatableIgnored
    var startTime: Date // Not animated

    @AnimatableIgnored
    var debugEnabled: Bool // Not animated

    var body: some View {
        VStack {
            Text(title)
            ProgressBar(value: progress)
            if debugEnabled {
                Text("Started: \(startTime.formatted())")
            }
        }
    }
}

Real-World Use Case

@Animatable works for any numeric display — stock prices, heart rate, scores, timers, progress bars:

@MainActor
@Animatable
struct AnimatedValueView: View {
    var value: Double
    var changePercent: Double

    @AnimatableIgnored
    var label: String

    var body: some View {
        VStack(alignment: .trailing) {
            Text("\(value, format: .number.precision(.fractionLength(2)))")
                .font(.title)
            Text("\(changePercent > 0 ? "+" : "")\(changePercent, format: .percent)")
                .foregroundStyle(changePercent > 0 ? .green : .red)
        }
    }
}

// Usage
AnimatedValueView(value: currentPrice, changePercent: 0.025, label: "Price")
    .animation(.spring(duration: 0.8), value: currentPrice)

Part 4: Animation Types

Timing Curve Animations

Timing curve animations use bezier curves to control the speed of animation over time.

Built-in presets
.animation(.linear)          // Constant speed
.animation(.easeIn)          // Starts slow, ends fast
.animation(.easeOut)         // Starts fast, ends slow
.animation(.easeInOut)       // Slow start and end, fast middle
Custom timing curves
let customCurve = UnitCurve(
    startControlPoint: CGPoint(x: 0.2, y: 0),
    endControlPoint: CGPoint(x: 0.8, y: 1)
)

.animation(.timingCurve(customCurve, duration: 0.5))
Duration

All timing curve animations accept an optional duration:

.animation(.easeInOut(duration: 0.3))
.animation(.linear(duration: 1.0))

Default: 0.35 seconds

Spring Animations

Spring animations use physics simulation to create natural, organic motion.

Built-in presets
.animation(.smooth)     // No bounce (default since iOS 17)
.animation(.snappy)     // Small amount of bounce
.animation(.bouncy)     // Larger amount of bounce
Custom springs
.animation(.spring(duration: 0.6, bounce: 0.3))

Parameters

  • duration — Perceived animation duration
  • bounce — Amount of bounce (0 = no bounce, 1 = very bouncy)

Much more intuitive than traditional spring parameters (mass, stiffness, damping).

Higher-Order Animations

Modify base animations to create complex effects.

Delay
.animation(.spring.delay(0.5))

Waits 0.5 seconds before starting the animation.

Repeat
.animation(.easeInOut.repeatCount(3, autoreverses: true))
.animation(.linear.repeatForever(autoreverses: false))

Repeats the animation multiple times or infinitely.

Speed
.animation(.spring.speed(2.0))  // 2x faster
.animation(.spring.speed(0.5))  // 2x slower

Multiplies the animation speed.

Default Animation Changes (iOS 17+)

Before iOS 17

withAnimation {
    // Used timing curve by default
}

iOS 17+

withAnimation {
    // Uses .smooth spring by default
}

Why the change: Spring animations feel more natural and preserve velocity when interrupted.

Recommendation: Embrace springs. They make your UI feel more responsive and polished.


Part 5: Transaction System

withAnimation

The most common way to trigger an animation.

Button("Scale Up") {
    withAnimation(.spring) {
        scale = 1.5
    }
}

How it works

  1. withAnimation opens a transaction
  2. Sets the animation in the transaction dictionary
  3. Executes the closure (state changes)
  4. Transaction propagates down the view hierarchy
  5. Animatable attributes check for animation and interpolate
Explicit animation
withAnimation(.spring(duration: 0.6, bounce: 0.4)) {
    isExpanded.toggle()
}
No animation
withAnimation(nil) {
    // Changes happen immediately, no animation
    resetState()
}

animation() View Modifier

Apply animations to specific values within a view.

Basic usage
Circle()
    .fill(isActive ? .blue : .gray)
    .animation(.spring, value: isActive)

How it works: Animation only applies when isActive changes. Other state changes won't trigger this animation.

Multiple animations on same view
Circle()
    .scaleEffect(scale)
    .animation(.bouncy, value: scale)
    .opacity(opacity)
    .animation(.easeInOut, value: opacity)

Different animations for different properties.

Scoped Animations (iOS 17+)

Narrowly scope animations to specific animatable attributes.

Problem with old approach
struct AvatarView: View {
    var selected: Bool

    var body: some View {
        Image("avatar")
            .scaleEffect(selected ? 1.5 : 1.0)
            .animation(.spring, value: selected)
            // ⚠️ If image also changes when selected changes,
            //    image transition gets animated too (accidental)
    }
}
Solution: Scoped animation
struct AvatarView: View {
    var selected: Bool

    var body: some View {
        Image("avatar")
            .animation(.spring, value: selected) {
                $0.scaleEffect(selected ? 1.5 : 1.0)
            }
            // ✅ Only scaleEffect animates, image transition doesn't
    }
}

How it works

  • Animation only applies to attributes in the closure
  • Other attributes are unaffected
  • Prevents accidental animations

Custom Transaction Keys

Define custom TransactionKey types to propagate context through the transaction system. Use withTransaction to set values and .transaction modifier to read them. This enables applying different animations based on how a state change was triggered (tap vs programmatic).


Part 6: Advanced Topics

CustomAnimation Protocol

Implement your own animation algorithms.

protocol CustomAnimation {
    // Calculate current value
    func animate<V: VectorArithmetic>(
        value: V,
        time: TimeInterval,
        context: inout AnimationContext<V>
    ) -> V?

    // Optional: Should this animation merge with previous?
    func shouldMerge<V>(previous: Animation, value: V, time: TimeInterval, context: inout AnimationContext<V>) -> Bool

    // Optional: Current velocity
    func velocity<V: VectorArithmetic>(
        value: V,
        time: TimeInterval,
        context: AnimationContext<V>
    ) -> V?
}
Example: Linear timing curve
struct LinearAnimation: CustomAnimation {
    let duration: TimeInterval

    func animate<V: VectorArithmetic>(
        value: V,              // Delta vector: target - current
        time: TimeInterval,
        context: inout AnimationContext<V>
    ) -> V? {
        if time >= duration { return nil }
        return value.scaled(by: time / duration)
    }
}

Critical understanding: value is the delta vector (target - current), not the target. Return nil when done. SwiftUI adds the scaled delta to the current value automatically.

Animation Merging Behavior

What happens when a new animation starts before the previous one finishes?

Timing curve animations (default: don't merge)
func shouldMerge(...) -> Bool {
    return false // Default implementation
}

Behavior: Both animations run together, results are combined additively.

Example

  • First tap: animate 1.0 → 1.5 (running)
  • Second tap (before finish): animate 1.5 → 1.0
  • Result: Both animations run, values combine
Spring animations (merge and retarget)
func shouldMerge(...) -> Bool {
    return true // Springs override this
}

Behavior: New animation incorporates state of previous animation, preserving velocity.

Example

  • First tap: animate 1.0 → 1.5 with velocity V
  • Second tap (before finish): retarget to 1.0, preserving current velocity V
  • Result: Smooth transition, no sudden velocity change

Why springs feel more natural: They preserve momentum when interrupted.


Part 7: Multi-Step Animations (iOS 17+)

PhaseAnimator

Cycles through a sequence of phases, applying different modifiers at each phase. Each phase transition is independently animated.

PhaseAnimator([false, true]) { phase in
    Image(systemName: "star.fill")
        .scaleEffect(phase ? 1.5 : 1.0)
        .opacity(phase ? 1.0 : 0.5)
        .rotationEffect(.degrees(phase ? 360 : 0))
} animation: { phase in
    phase ? .spring(duration: 0.8, bounce: 0.3) : .easeInOut(duration: 0.4)
}

How it works: Begins at first phase, animates to second, then loops. The animation closure returns the animation used to transition INTO that phase. Phases can be any Equatable type — use an enum for complex multi-step sequences:

enum PulsePhase: CaseIterable { case idle, expand, contract }

PhaseAnimator(PulsePhase.allCases) { phase in
    Circle()
        .scaleEffect(phase == .expand ? 1.3 : phase == .contract ? 0.9 : 1.0)
}

Trigger: Add a trigger parameter to run the animation only when a value changes (instead of looping continuously).

KeyframeAnimator

Provides per-property keyframe tracks for precise, timeline-based animations. More control than PhaseAnimator.

struct AnimationValues {
    var scale: Double = 1.0
    var rotation: Angle = .zero
    var yOffset: Double = 0
}

KeyframeAnimator(initialValue: AnimationValues()) { values in
    Image(systemName: "heart.fill")
        .scaleEffect(values.scale)
        .rotationEffect(values.rotation)
        .offset(y: values.yOffset)
} keyframes: { _ in
    KeyframeTrack(\.scale) {
        SpringKeyframe(1.5, duration: 0.3)
        SpringKeyframe(1.0, duration: 0.3)
    }
    KeyframeTrack(\.rotation) {
        LinearKeyframe(.degrees(15), duration: 0.15)
        LinearKeyframe(.degrees(-15), duration: 0.3)
        LinearKeyframe(.zero, duration: 0.15)
    }
    KeyframeTrack(\.yOffset) {
        CubicKeyframe(-20, duration: 0.3)
        CubicKeyframe(0, duration: 0.3)
    }
}

Keyframe types: LinearKeyframe (constant velocity), SpringKeyframe (spring physics), CubicKeyframe (bezier curves), MoveKeyframe (instant jump, no interpolation).

vs PhaseAnimator: Use PhaseAnimator for simple state cycling. Use KeyframeAnimator when different properties need independent timing.

.transition()

Defines how a view animates when inserted/removed from the view hierarchy.

if showDetail {
    DetailView()
        .transition(.slide)                          // Slide in/out
        .transition(.scale.combined(with: .opacity)) // Combine transitions
        .transition(.move(edge: .bottom))            // Move from edge
        .transition(.asymmetric(                     // Different in/out
            insertion: .scale.combined(with: .opacity),
            removal: .opacity
        ))
}

Requires animation context — wrap the state change in withAnimation or use .animation() modifier. Without animation, the view appears/disappears instantly.

matchedGeometryEffect

Smoothly animate a view's frame between two positions in the hierarchy. Commonly used for hero transitions and shared element animations.

@Namespace private var animation

// Source
if !isExpanded {
    RoundedRectangle(cornerRadius: 10)
        .matchedGeometryEffect(id: "card", in: animation)
        .frame(width: 100, height: 100)
}

// Destination
if isExpanded {
    RoundedRectangle(cornerRadius: 20)
        .matchedGeometryEffect(id: "card", in: animation)
        .frame(width: 300, height: 400)
}

Key rules: Same id + same Namespace = matched pair. Only one view with a given ID should be isSource: true (default) at a time. Wrap state change in withAnimation for smooth interpolation.

contentTransition

Animates changes to text and symbol content within a view (iOS 16+).

Text(value, format: .number)
    .contentTransition(.numericText(countsDown: value < previous))

Image(systemName: isFavorite ? "heart.fill" : "heart")
    .contentTransition(.symbolEffect(.replace))

Part 8: Zoom Transitions (iOS 18+)

Overview

iOS 18 introduces the zoom transition, where a tapped cell morphs into the incoming view. This transition is continuously interactive—users can grab and drag the view during or after the transition begins.

Key benefit In parts of your app where you transition from a large cell, zoom transitions increase visual continuity by keeping the same UI elements on screen across the transition.

SwiftUI Implementation

Two steps to adopt zoom transitions:

Step 1: Declare the transition style on the destination
NavigationLink {
    BraceletEditor(bracelet)
        .navigationTransition(.zoom(sourceID: bracelet.id, in: namespace))
} label: {
    BraceletPreview(bracelet)
}
Step 2: Mark the source view
BraceletPreview(bracelet)
    .matchedTransitionSource(id: bracelet.id, in: namespace)
Complete example
struct BraceletListView: View {
    @Namespace private var braceletList
    let bracelets: [Bracelet]

    var body: some View {
        NavigationStack {
            ScrollView {
                LazyVGrid(columns: [GridItem(.adaptive(minimum: 150))]) {
                    ForEach(bracelets) { bracelet in
                        NavigationLink {
                            BraceletEditor(bracelet: bracelet)
                                .navigationTransition(
                                    .zoom(sourceID: bracelet.id, in: braceletList)
                                )
                        } label: {
                            BraceletPreview(bracelet: bracelet)
                        }
                        .matchedTransitionSource(id: bracelet.id, in: braceletList)
                    }
                }
            }
        }
    }
}

UIKit Implementation

Set preferredTransition =.zoom {context in...} on the pushed view controller. The closure returns the source view and is called on both zoom in and zoom out — capture a stable identifier (model object), not a view directly.

Presentations

Zoom transitions also work with fullScreenCover and sheet:

.fullScreenCover(item: $selectedBracelet) { bracelet in
    BraceletEditor(bracelet: bracelet)
        .navigationTransition(.zoom(sourceID: bracelet.id, in: namespace))
}

Styling the Source View

.matchedTransitionSource(id: bracelet.id, in: namespace) { source in
    source.cornerRadius(8.0).shadow(radius: 4)
}

Fluid Transition Lifecycle

Push transitions cannot be cancelled — when interrupted, they convert to pop transitions. The view controller always reaches the Appeared state. Don't guard against overlapping transitions; let the system handle them.


Part 9: UIKit/AppKit Animation Bridging (iOS 18+)

Overview

iOS 18 enables using SwiftUI Animation types to animate UIKit and AppKit views. This provides access to the full suite of SwiftUI animations, including custom animations.

Basic Usage

// Old way
UIView.animate(withDuration: 0.5, delay: 0,
               usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5) {
    bead.center = endOfBracelet
}

// New way: Use SwiftUI Animation type
UIView.animate(.spring(duration: 0.5)) {
    bead.center = endOfBracelet
}

All SwiftUI animations work: .linear, .easeIn/Out, .spring, .smooth, .snappy, .bouncy, .repeatForever(), and custom animations.

Architecture note: Unlike old UIKit APIs, no CAAnimation is generated — presentation values are animated directly.


Part 10: UIViewRepresentable Animation Bridging (iOS 18+)

The Problem

When wrapping UIKit views in SwiftUI, animations don't automatically bridge:

struct BeadBoxWrapper: UIViewRepresentable {
    @Binding var isOpen: Bool

    func updateUIView(_ box: BeadBox, context: Context) {
        // ❌ Animation on binding doesn't affect UIKit
        box.lid.center.y = isOpen ? -100 : 100
    }
}

// Usage
BeadBoxWrapper(isOpen: $isOpen)
    .animation(.spring, value: isOpen)  // No effect on UIKit view

The Solution: context.animate()

Use context.animate() to bridge SwiftUI animations:

struct BeadBoxWrapper: UIViewRepresentable {
    @Binding var isOpen: Bool

    func makeUIView(context: Context) -> BeadBox {
        BeadBox()
    }

    func updateUIView(_ box: BeadBox, context: Context) {
        // ✅ Bridges animation from Transaction to UIKit
        context.animate {
            box.lid.center.y = isOpen ? -100 : 100
        }
    }
}

How It Works

  1. SwiftUI stores animation info in the current Transaction
  2. context.animate() reads the Transaction's animation
  3. Applies that animation to UIView changes in the closure
  4. If no animation in Transaction, changes happen immediately (no animation)

Key Behavior

context.animate {
    // Changes here
} completion: {
    // Called when animation completes
    // If not animated, called immediately inline
}

Works whether animated or not — safe to always use this pattern.

Perfect Synchronization

A single animation running across SwiftUI Views and UIViews runs perfectly in sync. This enables seamless mixed hierarchies.


Part 11: Gesture-Driven Animations (iOS 18+)

Automatic Velocity Preservation

SwiftUI animations automatically preserve velocity through animation merging — no manual velocity calculation needed:

// UIKit with SwiftUI animations
func handlePan(_ gesture: UIPanGestureRecognizer) {
    switch gesture.state {
    case .changed:
        UIView.animate(.interactiveSpring) {
            bead.center = gesture.location(in: view)
        }
    case .ended:
        UIView.animate(.spring) {  // Inherits velocity automatically
            bead.center = endOfBracelet
        }
    default: break
    }
}

// Pure SwiftUI equivalent
DragGesture()
    .onChanged { value in
        withAnimation(.interactiveSpring) { position = value.location }
    }
    .onEnded { _ in
        withAnimation(.spring) { position = targetPosition }
    }

Each .interactiveSpring retargets the previous animation, and the final .spring inherits the accumulated velocity for smooth deceleration.



Troubleshooting

Property Not Animating

Check in order:

  1. Type conforms to VectorArithmetic? — Int can't animate; use Double/Float
  2. Animation modifier present? — Need .animation(.spring, value: x) or withAnimation
  3. Correct value tracked? — .animation(.spring, value: progress) not .animation(.spring, value: title)
  4. View conforms to Animatable? — Custom views need @Animatable (iOS 26+) or manual animatableData

Animation Stuttering

Custom Animatable conformance calls body every frame on main thread. Use built-in effects (.opacity(), .scaleEffect()) when possible — they run off-main-thread. Profile with Instruments for complex cases.

Unexpected Animation Merging

Spring animations merge by default, preserving velocity. Use timing curve animations (.easeInOut) if you don't want merging behavior. See Animation Merging Behavior section above.


Resources

WWDC: 2023-10156, 2023-10157, 2023-10158, 2024-10145, 2025-256

Docs: /swiftui/animatable, /swiftui/animation, /swiftui/vectorarithmetic, /swiftui/transaction, /swiftui/view/navigationtransition(*:), /swiftui/view/matchedtransitionsource(id:in:configuration:), /uikit/uiview/animate(*:changes:completion:)

Skills: axiom-swiftui-26-ref, axiom-swiftui-nav-ref, axiom-swiftui-performance, axiom-swiftui-debugging, axiom-sf-symbols-ref

平台分布

Claude Code

25.14%
按下载量换算445

OpenCode

24.35%
按下载量换算431

Codex

18.19%
按下载量换算322

Antigravity

12.25%
按下载量换算217

Cursor

7.21%
按下载量换算128

Gemini CLI

3.1%
按下载量换算55

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

继续浏览同类 Skills