glassEffectTransition
Associates a glass effect transition with any glass effects defined within this view.
Declaration
compose().glassEffectTransition(
transition: SwiftUI.GlassEffectTransition
)@MainActor @preconcurrency func glassEffectTransition(
_ transition: GlassEffectTransition
) -> some ViewParameters
transition*SwiftUI.GlassEffectTransition
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.
- animationApplies the given animation to all animatable values within the body closure.
- contentTransitionModifies the view to use a given transition as its method of animating changes to the contents of its views.
- 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.