---
title: "animation(_:body:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/animation(_:body:)"
---

# animation(_:body:)

Applies the given animation to all animatable values within the body closure.

## Declaration

```swift
nonisolated func animation<V>(_ animation: Animation?, @ContentBuilder body: (PlaceholderContentView<Self>) -> V) -> some View where V : View

```

## Discussion

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

### Adding state-based animation to a view

- [animation(_:)](swiftui/view/animation(_:).md)
- [animation(_:value:)](swiftui/view/animation(_:value:).md)
