<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/keyframeAnimator(initialValue:trigger:content:keyframes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE16keyframeAnimator12initialValue7trigger7content9keyframesQrqd___qd_0_qd_1_AA018PlaceholderContentC0VyxG_qd__tYbcqd_2_qd__ct0G0Qyd_2_Rsd__SQRd_0_AaBRd_1_AA9KeyframesRd_2_r2_lF"
  },
  "title" : "keyframeAnimator(initialValue:trigger:content:keyframes:)"
}
-->

# keyframeAnimator(initialValue:trigger:content:keyframes:)

Plays the given keyframes when the given trigger value changes, updating
the view using the modifiers you apply in `body`.

```
nonisolated func keyframeAnimator<Value>(initialValue: Value, trigger: some Equatable, @ContentBuilder content: @escaping @Sendable (PlaceholderContentView<Self>, Value) -> some View, @KeyframesBuilder<Value> keyframes: @escaping (Value) -> some Keyframes) -> some View
```

## Parameters

`initialValue`

The initial value that the keyframes will animate
from.

`trigger`

A value to observe for changes.

`content`

A content builder closure that takes two parameters. The first
parameter is a proxy value representing the modified view. The
second parameter is the interpolated value generated by the
keyframes.

`keyframes`

Keyframes defining how the value changes over time. The
current value of the animator is the single argument, which is
equal to `initialValue` when the view first appears, then is equal
to the end value of the previous keyframe animation on subsequent
calls.

## Discussion

Note that the `content` closure will be updated on every frame while
animating, so avoid performing any expensive operations directly within
`content`.

If the trigger value changes while animating, the `keyframes` closure
will be called with the current interpolated value, and the keyframes
that you return define a new animation that replaces the old one. The
previous velocity will be preserved, so cubic or spring keyframes will
maintain continuity from the previous animation if they do not specify
a custom initial velocity.

When a keyframe animation finishes, the animator will remain at the
end value, which becomes the initial value for the next animation.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)