小编Mat*_*uez的帖子

拖放列表以在 SwiftUI 上重新排序

如何在 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

12
推荐指数
3
解决办法
6569
查看次数

标签 统计

swiftui ×1