glassEffectTransition

Associates a glass effect transition with any glass effects defined within this view.

View ModifieriOS 26.0+macOS 26.0+tvOS 26.0+watchOS 26.0+glassEffectTransition(_:) in SwiftUI

Declaration

React
compose().glassEffectTransition(
  transition: SwiftUI.GlassEffectTransition
)
Swift
@MainActor @preconcurrency func glassEffectTransition(
    _ transition: GlassEffectTransition
) -> some View

Parameters

Discussion

You use this modifier with the View.glassEffect(_:in:) view modifier and GlassEffectContainer view. When used together, SwiftUI will use the provided transition to apply changes to the glass effect when you add or remove views with these effects from the view hierarchy.

In the example below, the notepad image will transition into and out of the pencil image when the isExpanded variable changes.

var isExpanded: Bool
@Namespace private var namespace

var body: some View {
    GlassEffectContainer(spacing: 10.0) {
        HStack(spacing: 10.0) {
            Image(systemName: "pencil")
                .frame(width: 20.0, height: 20.0)
                .glassEffect()
                .glassEffectID("pencil", in: namespace)

                if isExpanded {
                    Image(systemName: "note")
                        .frame(width: 20.0, height: 20.0)
                        .glassEffect()
                        .glassEffectID("note", in: namespace)
                        .glassEffectTransition(.matchedGeometry)
                }
            }
        }
    }
}

See also

More in Animation.