【发布时间】:2022-06-14 10:31:57
【问题描述】:
CoreLocationUI 中的 LocationButton 似乎在滚动时中断。
这是一个例子:
import SwiftUI
import CoreLocationUI
struct LocationButtonBrokenView: View {
@State private var txt: String = "Test"
var body: some View {
List {
Group {
Text("Hello, World!")
VStack {
Text("Where are you?")
HStack {
TextField("Text", text: $txt)
LocationButton() {
print("Get location")
}
}
}
ForEach(0 ..< 8, id: \.self) {_ in
Text("Hello, World!")
}
}
Group {
ForEach(0 ..< 9, id: \.self) {_ in
Text("Hello, World!")
}
}
}
}
}
struct LocationButtonBrokenView_Previews: PreviewProvider {
static var previews: some View {
LocationButtonBrokenView()
}
}
第一次加载视图时,一切都按预期呈现:
但是当你向下滚动和备份之后它就是垃圾:
【问题讨论】:
-
我使用 Group 只是为了方便添加足够的项目以强制视图滚动。组与此处的问题无关,并且问题出现在我的实际代码中没有组。
-
尝试删除 id:\self 并制作自定义子视图而不是组。但在我看来,Vstack 已经失去了它的高度。
标签: ios swift swiftui core-location