import SwiftUI
struct ContentView: View {
var body: some View {
ScrollViewReader { proxy in
ScrollView {
VStack {
Color.yellow
.frame(height: 900)
ScrollButton(proxy: proxy)
Color.yellow
.frame(height: 900)
}
.padding(.horizontal, 40)
}
}
}
}
struct ScrollButton: View {
let proxy: ScrollViewProxy
@Namespace var bottomId
var body: some View {
VStack {
Button("Scroll") {
withAnimation {
proxy.scrollTo(bottomId, anchor: .top)
}
}
}.id(bottomId)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}