<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "visionOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/HoverEffectContent/animation(_:body:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI18HoverEffectContentPAAE9animation_4bodyQrAA9AnimationVSg_qd__AA05EmptycdE0VXEtAaBRd__lF"
  },
  "title" : "animation(_:body:)"
}
-->

# animation(_:body:)

Applies the given [`Animation`](/documentation/SwiftUI/Animation) to all effects within the `body` closure.

```
func animation(_ animation: Animation?, body: (EmptyHoverEffectContent) -> some HoverEffectContent) -> some HoverEffectContent
```

## Parameters

`animation`

The animation to use for the effect transition. If `nil`
the effects will not animate.

`body`

A block used to specify the effects to animate. You must use
the provided content to build the effects, or behavior is undefined.

## Return Value

A new effect that combines the effects defined in `body` with

## Discussion

Any effects defined within the `body` closure will be combined with this
effect, and the `animation` will used to animate those effects’ changes
when the effects are applied.

In the following example, the view will use the `.easeIn` animation when
activating the effect, but `.easeOut` when the effect becomes inactive:

```
Color.red
    .hoverEffect { effect, isActive, proxy in
        effect.animation(isActive ? .easeIn : .easeOut) {
            $0.opacity(isActive ? 1 : 0.5)
        }
    }
```

---

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)