Home > AI > IOS > SwiftUI >

add or remove a view with animation

struct ContentView: View {
    @State private var isPresented = false

    var body: some View {
        VStack {
            Button("Press to show details") {
                withAnimation {
                    isPresented.toggle()
                }
            }

            if isPresented {

                // Starts small and grows to full size.
                Text("Details go here.")
                    .transition(.scale)
            }
        }
    }
}

Leave a Reply