代码之家  ›  专栏  ›  技术社区  ›  Duck

SwiftUI列表项装饰影响要删除的幻灯片

  •  0
  • Duck  · 技术社区  · 5 年前

    我有一个列表,其中包含以下项目:

     List {
      ForEach(filteredItems, id: \.self) { item in
         Text(item.termLowerCase)
      .font(fontItems)
      .foregroundColor(.white)
      .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
      .contentShape(Rectangle())
      .onTapGesture {
         // doSomething()
      }
      .onDelete { offsets in
       print("deleting"
      }
      .listRowBackground(
        Group {
          if item == selectedItem {
            Color("selectedColor").mask(RoundedRectangle(cornerRadius: 20))
          } else {
            Color.clear
          }
        }
        .padding(EdgeInsets(top: 0, leading: 5, bottom: 0, trailing: 5))
      )
    

    此代码生成如下元素,包括选定元素的圆角。

    enter image description here

    我该如何解决这个问题?

    1. 我要整个牢房,从左到右,可点击,而不仅仅是文字。
    0 回复  |  直到 5 年前
        1
  •  1
  •   Asperi    5 年前

    你可能被附了 .onDelete ForEach (不适用于世界其他地区)

      ForEach(filteredItems, id: \.self) { item in
         Text(item.termLowerCase)
      }
      .onDelete { offsets in    // << here !!
        print("deleting"
      }