如何通过单击按钮SwiftUI iOS 13滚动到ScrollView的底部

如何通过单击按钮SwiftUI iOS 13滚动到ScrollView的底部,swiftui,Swiftui,我知道这已经在iOS 14中解决了,但我目前的项目是在iOS 13中,我们必须尽快发布它。我尝试了堆栈中的多种方法,但没有成功。我只想单击一个按钮并滚动到ScrollView的底部,就这样。我很惊讶SwiftUI中没有内置的函数 struct ContentView: View { var items = [Color.red, Color.orange, Color.yellow, Color.green,Color.blue, Color.purple, Color.red, Color.o

我知道这已经在iOS 14中解决了,但我目前的项目是在iOS 13中,我们必须尽快发布它。我尝试了堆栈中的多种方法,但没有成功。我只想单击一个按钮并滚动到ScrollView的底部,就这样。我很惊讶SwiftUI中没有内置的函数

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)
            
        }
        
    }
    
}
}

如果有人能帮忙的话

经过几个小时的搜索,我发现这个神奇的东西完全符合你的要求

ScrollView{ proxy in
            Button("click"){
                proxy.scrollTo(200)
            }.foregroundColor(.red)
            ForEach(0..<1000){ index in
                Text("\(index)")
                    .scrollId(index)
            }
        }
ScrollView{中的代理
按钮(“点击”){
proxy.scrollTo(200)
}.foregroundColor(.red)

Oracle(0…考虑方法,<代码> ListScLink代理>代码>也适用于<代码> ScLabVIEW 。或者这个主题为自定义滚动视图我已经尝试了一个解决方案,我会尝试另一个。谢谢。