【发布时间】:2020-05-28 11:34:54
【问题描述】:
(Swift 5,SwiftUI) 如果我有以下 VStack 代码:
struct ContentView: View {
var body: some View {
ScrollView {
VStack(alignment: .leading) {
//Inside of VStack
}.padding()
.padding(.bottom, keyboard.currentHeight)
.edgesIgnoringSafeArea(.bottom)
.animation(.easeOut(duration: 0.16))
}
}
}
如何通过函数将Text()s动态添加到VStack并相应地更新ScrollView的高度?
函数(通过按下按钮调用):
func add() -> Void {
//Adds a Text() element to the VStack. The content of the Text() is received from an API
//call, so it can't be hardcoded.
}
我正在寻找一种将 Text() 元素添加到我的 VStack 的简单方法。我在谷歌上广泛搜索了这个问题,但没有发现与这个微不足道的问题类似的东西。任何帮助将不胜感激。
【问题讨论】:
-
这是相关的:stackoverflow.com/questions/61895745/…。简而言之,您不添加视图,而是修改状态,视图对其做出反应。
标签: swift uiscrollview swiftui vstack