transition

Associates a transition with the view.

View ModifieriOS 13.0+macOS 10.15+tvOS 13.0+watchOS 6.0+

Overloads

2 ways to call compose().transition(). Each is one SwiftUI overload, picked by the arguments you pass.

React
compose().transition(t: SwiftUI.AnyTransition)
Swift
nonisolated func transition(_ t: AnyTransition) -> some View

Parameters

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

More in Animation.