如何在 SwiftUI 上添加拖放以重新排序行?只是一个没有“编辑模式”的干净解决方案。这里有一个例子:
更新
我在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) { …
Run Code Online (Sandbox Code Playgroud) swiftui ×1