【发布时间】:2019-06-27 11:59:21
【问题描述】:
如何在 SwiftUI 上添加拖放以重新排序行? 只是一个没有“编辑模式”的干净解决方案。 Here 一个例子:
更新
我在The SwiftUI Lab 上问了这个问题,作者回复了这段代码。仅适用于 iPad
import SwiftUI
struct Fruit: Identifiable {
let id = UUID()
let name: String
let image: String
}
struct ContentView: View {
@State var selection: Set<UUID> = []
@State private var fruits = [
Fruit(name: "Apple", image: "apple"),
Fruit(name: "Banana", image: "banana"),
Fruit(name: "Grapes", image: "grapes"),
Fruit(name: "Peach", image: "peach"),
Fruit(name: "Kiwi", image: "kiwi"),
]
var body: some View {
VStack {
NavigationView {
List(selection: $selection) {
ForEach(fruits) { fruit in
HStack {
Image(fruit.image)
.resizable()
.frame(width: 30, height: 30)
Text(fruit.name)
}
}
.onMove { _, _ in }
}
.navigationBarTitle("Fruits (Top)")
}
}
}
}
【问题讨论】:
标签: swiftui