Home > front end >  How to drag view for expand and collaps in SwiftUI?
How to drag view for expand and collaps in SwiftUI?

Time:02-21

i am trying to expand and collaps Vstack on the click of button as well as by using Drag.

I am able to to it using button click by below code but not sure hoe to use drag gesture.

import SwiftUI

struct ContentView: View {

    @State private var Expand = false

    var body: some View {

        VStack {
            Color
                .red
        }
        .overlay(
            GeometryReader { geometry in
                VStack() {
                    VStack {
                        Text("1")
                        if Expand {
                            Text("2")
                            Text("3")
                            Text("4")
                            Text("5")
                        }
                    }
                    Button(Expand ? "Collaps" : "Expand") {
                        Expand.toggle()
                    }
                }
                .background(.yellow)
                .frame(maxWidth: .infinity)
            }

        )
    }
}

enter image description here

enter image description here

CodePudding user response:

check it! enter image description here

  • Related