TechnologiesSwiftUIScrolling

AnimationTimelineSchedule struct

iOSmacOStvOSwatchOSvisionOSiOS 15.0+✓ renders

A pausable schedule of dates updating at a frequency no more quickly than

How it works

AnimationTimelineSchedule is a timeline schedule that paces a TimelineView's updates to match the cadence of the system's animations rather than to fixed clock intervals. Use it when you want a view to redraw continuously and smoothly — driving frame-by-frame visuals like rotations, oscillations, or other time-derived effects — at whatever rate the display and animation system can sustain. Because it ties refreshes to the animation loop, you reach for it whenever you need fluid, per-frame motion computed from the current time, instead of a discrete tick at a set interval. You rarely name the type directly; you select it through the TimelineView.ScheduleProvider convenience .animation.

  1. Select the schedule with TimelineView(.animation)

    AnimationTimelineSchedule is supplied to a TimelineView as its schedule argument, which decides when the view's content closure re-evaluates. The static member .animation is the convenient way to construct it, as in TimelineView(.animation), telling the timeline to refresh in lockstep with animations rather than on a fixed cadence.

  2. Read the current time from the update context

    Each refresh the schedule triggers hands your closure a context whose date reflects the moment of that update. You derive a continuous value from it — here context.date.timeIntervalSinceReferenceDate is stored in t — giving you an ever-advancing number to map onto whatever visual property you want to animate.

  3. Compute a per-frame value to drive the view

    Because AnimationTimelineSchedule redraws so frequently, you can turn the time into smoothly changing geometry inside the closure. The example folds t into a repeating sweep with Angle.degrees(t.truncatingRemainder(dividingBy: 2) * 180), producing an angle that cycles as time advances.

  4. Apply the time-derived value in the content

    The view returned from the timeline closure binds the computed value to a modifier so each refresh paints a new frame. Here .rotationEffect(angle) spins the Image(systemName: "gearshape.fill"), so the schedule's animation-paced updates surface as visible, continuous motion.

  5. Configure the rate and the surrounding view as needed

    AnimationTimelineSchedule paces itself to the animation system, but its updates only matter where the timeline's content reads time. Everything outside the closure — like the VStack and .padding() wrapping the gear — is ordinary layout that hosts the animated content the schedule keeps refreshing.

Try it — Change Angle.degrees(t.truncatingRemainder(dividingBy: 2) * 180) to Angle.degrees(t * 90) to make the gear spin steadily and continuously, exposing how the schedule feeds an ever-advancing time into the view.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

AnimationTimelineSchedule.swift
struct AnimationTimelineScheduleDemo: View {
    var body: some View {
        TimelineView(.animation) { context in
            let t = context.date.timeIntervalSinceReferenceDate
            let angle = Angle.degrees(t.truncatingRemainder(dividingBy: 2) * 180)
            VStack(spacing: 16) {
                Text("AnimationTimelineSchedule")
                    .font(.headline)
                Image(systemName: "gearshape.fill")
                    .font(.system(size: 60))
                    .foregroundStyle(.blue)
                    .rotationEffect(angle)
                Text("Redraws in step with animations")
                    .font(.caption)
                    .foregroundStyle(.secondary)
            }
        }
        .padding()
    }
}
Live preview
AnimationTimelineSchedule Redraws in step with animations
AnimationTimelineSchedule Redraws in step with animations
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →