1

I am looking to replicate finder functionality in SwiftUI. Currently I have ScrollView that has content inside it, but when I resize window the ScrollView scrolls and does not keep its initial scroll offset. Is there a way to keep the offset?

Here is a small example of what I have.

    ScrollView([.horizontal, .vertical], showsIndicators: true) {
        VStack {
            HStack {
                ForEach(1...100, id: \.self) { num in
                    Text("num")
                }
            }
            .frame(width: 1500, height: 200, alignment: .topLeading)
            .background(Color.red)
            HStack {
                ForEach(1...100, id: \.self) { num in
                    Text("duo")
                }
            }
            .frame(width: 1500, height: 200, alignment: .topLeading)
            .background(Color.blue)
            HStack {
                ForEach(1...100, id: \.self) { num in
                    Text("tre")
                }
            }
            .frame(width: 1500, height: 200, alignment: .topLeading)
            .background(Color.green)
            HStack {
                ForEach(1...100, id: \.self) { num in
                    Text("quat")
                }
            }
            .frame(width: 1500, height: 200, alignment: .topLeading)
            .background(Color.gray)
        }.frame(width: 1500, height: 1000, alignment: .topLeading)
    }
Jason Krowl
  • 84
  • 2
  • 15

1 Answers1

0

What you need to do is store the current item ID and then scroll down to that when ScrollView re-appears

Take a look at Save ScrollViews position and scroll back to it later (offset to position)

Suyash Medhavi
  • 1,135
  • 6
  • 18