DaisukeNagata / SwiftUI2.0

3 stars 0 forks source link

Scrollviewreader #2

Open DaisukeNagata opened 4 years ago

DaisukeNagata commented 4 years ago

https://developer.apple.com/documentation/swiftui/scrollviewreader

スクリーンショット 2020-06-28 8 30 24
DaisukeNagata commented 4 years ago

this is code

struct ContentView: View {
    var body: some View {
        ScrollViewReader { scrollOffset in
            ScrollView {
                LazyVStack(alignment: .center) {
                    ForEach(1...100, id: \.self) {
                        Text("Row \($0)")

                    }
                    .onChange(of: /*@START_MENU_TOKEN@*/"Value"/*@END_MENU_TOKEN@*/) { value in
                        print(scrollOffset.scrollTo(77, anchor: .center))
                    }
                }
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
DaisukeNagata commented 4 years ago

It will be the coordinates of the specified location.