Contents

CustomHoverEffect

A type that represents how a view should change when a pointer hovers over a view, or when someone looks at the view.

Declaration

protocol CustomHoverEffect

Overview

Custom hover effects apply their inactive values when the effect is inactive, and their active values when the effect is active. For example, the following effect causes a view to be partially transparent when inactive, but animate to fully opaque when active:

struct FadeInHoverEffect: CustomHoverEffect {
    func body(content: Content) -> some CustomHoverEffect {
        content.hoverEffect { effect, isActive, proxy in
            effect.animation(.easeOut) {
                $0.opacity(isActive ? 1 : 0.5)
            }
        }
    }
}

This effect can be applied to a view using the hoverEffect(_:) modifier:

Color.red
    .hoverEffect(FadeInHoverEffect())

Hover effects do not affect a view’s layout, and may be applied to a view out-of-process. Therefore an effect’s current phase may not be visible within your app.

Topics

Getting built-in hover effects

Creating custom hover effects

Supporting types

Associated Types

Instance Methods

Type Aliases

Type Methods

See Also

Changing view appearance for hover events