是否可以像列表中一样对ScrollView中的项目进行“重新排序” /“移动”?我的游乐场在下面可以编译/运行,但是onDelete / onMove确实可以可视化任何用于删除/移动的删除按钮或汉堡包行吗?
是否有办法让我的代码在这里工作,以便至少使“ onMove”概念起作用?
注意-我注意到List和ScrollView(我认为)都支持协议DynamicViewContent,因此假设它应该工作(?)
运行代码后的图片:
代码(游乐场)
import SwiftUI
import PlaygroundSupport
let modelData: [String] = ["Eggs", "Milk", "Bread"]
struct ListTestNoDelete: View {
private func move(from uiStartIndexSet: IndexSet, to uiDestIndex: Int) {
print("On Move")
}
private func delete(at offsets : IndexSet) {
print("On Delete")
}
var body: some View {
NavigationView {
VStack {
ScrollView {
ForEach(modelData, id: \.self) { str in
HStack {
Image(systemName: "square")
Text(str)
Spacer()
}.padding(.horizontal, 3)
}
.onMove(perform: self.move)
.onDelete(perform: self.delete)
}
.environment(\.editMode, .constant(.active))
.navigationBarTitle( Text("Test") )
}
}
}
}
let listTest = ListTestNoDelete()
PlaygroundPage.current.liveView = UIHostingController(rootView: listTest)