SwiftUI onDrag调整Preivew图像的大小

时间:2020-10-09 12:10:40

标签: swiftui

enter image description here

我在LazyVGrid中使用Swiftui OnDrag和OnDrop对视图进行重新排序,但是我发现拖动视图时,预览图像会更小,背景会像我发布的图像一样透明,如何解决此错误? / p>

LazyVGrid(columns: columns, spacing: 24) {
        ForEach(widgets) { widget in
            
            ZStack(alignment: .topLeading) {
                Rectangle()
                    .fill(Color.blue)
                    .opacity(self.dragWidget?.id == widget.id ? 0.0001 : 1)
                    .frame(width: 300, height: 200)
                    .onDrag{
                        mainUIState.edit = false
                        self.dragWidget = widget
                        return NSItemProvider(object: String(widget.id) as NSString)
                    }
                    .onDrop(of: [UTType.text], delegate: DragRelocateDelegate(item: widget, listData: $widgets, current: $dragWidget))
                
            }

            if isExclusiveLine(data: widget, list: widgets) { Color.clear }
            
        }
    }

struct DragRelocateDelegate: DropDelegate {

    let item: Widget
    @Binding var listData: [Widget]
    @Binding var current: Widget?

    func dropEntered(info: DropInfo) {
       if item != current {
        let from = listData.firstIndex(of: current!)!
        let to = listData.firstIndex(of: item)!
        if listData[to].id != current!.id {
            listData.move(fromOffsets: IndexSet(integer: from),
                toOffset: to > from ? to + 1 : to)
        }
      }
    }

   func dropUpdated(info: DropInfo) -> DropProposal? {
      return DropProposal(operation: .move)
   }

   func performDrop(info: DropInfo) -> Bool {
      self.current = nil
      return true
  }
}

这是我的代码

0 个答案:

没有答案