首页 > 解决方案 > 如何使用列表视图在 swiftUI 中创建两列列表?

问题描述

我是 SwiftUI 的新手。我需要创建一个显示在两列中的列表。它更有可能是每行有两个项目的 collectionView。条件是我需要使用“列表”创建它,因为我需要在此列表中添加“拖放以重新排序”功能。

到目前为止,我已经使用 HStack 和 VStack 实现了它,但在这种情况下,没有选项可以拖动和重新排序列表。

这是我到目前为止所做的代码:

           ZStack{
              Button(action: {
                 }) {
                      HStack{
                         Image(systemName: "person.crop.circle.fill")
                         Text(font)
                             .font(.system(size: 13 ))
                         .foregroundColor(.black)
                            .frame(minWidth: UIScreen.main.bounds.size.width/4, maxWidth: UIScreen.main.bounds.size.width/4)
                         .padding(.horizontal)
                       }
                       .padding(10)
                     }
                     .foregroundColor(Color.black)
                     .background(Color.white)
                     .cornerRadius(8)
                     .background(
                     RoundedRectangle(cornerRadius: 5)
                         .fill(Color.white)
                         .shadow(color: .gray, radius: 2, x: 0, y: 2)
                     )
          }

我的问题是:如何在 SwiftUI Using List 中创建两列列表的集合视图类型?如果我使用 HStack 和 Stack 的实现听起来不错,那么:有没有办法实现拖放以重新排序列表功能?

我无法使用 LazyVGrid,因为我的要求是 ios13。

任何帮助将不胜感激。

谢谢!!

更新:我使用 swiftui 中的 UIViewRepresentable 包装的 UICollectionView 解决了它。

标签: drag-and-dropswiftui-list

解决方案


推荐阅读