Home > AI > IOS > SwiftUI >

add or remove a view with animation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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