View ModifieriOS 17.0+macOS 14.0+tvOS 17.0+watchOS 10.0+
Overloads
2 ways to call compose().animation(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().animation(
animation: SwiftUI.Animation | null,
options: {
body: ViewModifierChain;
}
)nonisolated func animation<V>(
_ animation: Animation?,
@ContentBuilder body: (PlaceholderContentView<Self>) -> V
) -> some View
where V : ViewParameters
animation*SwiftUI.Animation | nulloptions.body*ViewModifierChain
Discussion
Any modifiers applied to the content of body will be applied to this
view, and the animation will only be used on the modifiers defined in
the body.
The following code animates the opacity changing with an easeInOut animation, while the contents of MyView are animated with the implicit transaction's animation:
MyView(isActive: isActive)
.animation(.easeInOut) { content in
content.opacity(isActive ? 1.0 : 0.0)
}See also
More in Animation.
- contentTransitionModifies the view to use a given transition as its method of animating changes to the contents of its views.
- glassEffectTransitionAssociates a glass effect transition with any glass effects defined within this view.
- keyframeAnimatorLoops the given keyframes continuously, updating the view using the modifiers you apply in body.
- matchedGeometryEffectDefines a group of views with synchronized geometry using an identifier and namespace that you provide.
- matchedTransitionSourceIdentifies this view as the source of a navigation transition, such as a zoom transition.
- phaseAnimatorAnimates effects that you apply to a view over a sequence of phases that change continuously.
- scrollTransitionApplies the given transition, animating between the phases of the transition as this view appears and disappears within the visible region of the containing scroll view.
- springLoadingBehaviorSets the spring loading behavior this view.
- transitionAssociates a transition with the view.