transition(_:)
Associates a transition with the view.
Declaration
nonisolated func transition(_ t: AnyTransition) -> some View
Discussion
When this view appears or disappears, the transition will be applied to it, allowing for animating it in and out.
The following code will conditionally show MyView, and when it appears or disappears, will use a slide transition to show it.
if isActive {
MyView()
.transition(.slide)
}
Button("Toggle") {
withAnimation {
isActive.toggle()
}
}See Also
Defining transitions
TransitionTransitionPropertiesTransitionPhaseAsymmetricTransitionAnyTransitioncontentTransition(_:)contentTransitioncontentTransitionAddsDrawingGroupContentTransitionPlaceholderContentViewnavigationTransition(_:)NavigationTransitionmatchedTransitionSource(id:in:)matchedTransitionSource(id:in:configuration:)MatchedTransitionSourceConfiguration