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.
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
.animationis the convenient way to construct it, as inTimelineView(.animation), telling the timeline to refresh in lockstep with animations rather than on a fixed cadence.Read the current time from the update context
Each refresh the schedule triggers hands your closure a context whose
datereflects the moment of that update. You derive a continuous value from it — herecontext.date.timeIntervalSinceReferenceDateis stored int— giving you an ever-advancing number to map onto whatever visual property you want to animate.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
tinto a repeating sweep withAngle.degrees(t.truncatingRemainder(dividingBy: 2) * 180), producing ananglethat cycles as time advances.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 theImage(systemName: "gearshape.fill"), so the schedule's animation-paced updates surface as visible, continuous motion.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
VStackand.padding()wrapping the gear — is ordinary layout that hosts the animated content the schedule keeps refreshing.
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.
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()
}
}