1

这是代码:

struct ContentView: View {
    @State var names = ["A" , "B", "C", "D"]
    var body: some View {
        List {
            ForEach(names, id: \.self ) { name in
                Group {
                    testStruct(name: name)
                }
            }.onDelete(perform: removeItems)
        }
    }
    private func removeItems (indexSet: IndexSet) {
        names.remove(atOffsets: indexSet)
    }
}


struct testStruct: View , Identifiable {
    @State var name: String
    let id = UUID()
    var body: some View {
        HStack {
           Text(name)
           Spacer()
           Image(systemName: "folder.fill")
        }
    }
}

我无法在滑动 onDelete 时删除尾随的红色动画。有什么优雅的方法可以做到这一点。.animation() 似乎不起作用

4

0 回答 0