0

I know this has been solved in iOS 14 but my current project is in iOS 13 and we have to release it fast. I tried multiple approach from stack but no luck. I just want to click a button and scroll to the bottom of the ScrollView, thats it. I was surprised there is not built in function in SwiftUI for this !!!

struct ContentView: View {
var items = [Color.red, Color.orange, Color.yellow, Color.green,Color.blue, Color.purple, Color.red, Color.orange, Color.yellow, Color.green,Color.blue, Color.purple]

var body: some View {
    ZStack {
        ScrollView(Axis.Set.vertical, showsIndicators: false) {
            VStack {
                ForEach(self.items, id: \.self) { item in
                    // 3.
                    Circle()
                        .fill(item)
                        .frame(width: 100, height: 100)
                }
            }
        }
        
        VStack {
            Spacer()
            HStack {
                Spacer()
                Button(action: {
                    // scroll to bottom
                }) {
                    Text("Button")
                }
            }
            .padding(.trailing, 20)
            .padding(.bottom, 20)
            
        }
        
    }
    
}
}

If anybody could help

2

1 Answer 1

2

After a few hours search i found this amazing library that does exactly as you want

ScrollView{ proxy in
            Button("click"){
                proxy.scrollTo(200)
            }.foregroundColor(.red)
            ForEach(0..<1000){ index in
                Text("\(index)")
                    .scrollId(index)
            }
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.