我正在尝试为我的LazyHGridview. 当我尝试将视图放到另一个视图上时,视图的右上角会显示绿色圆圈内的“加号”图标。
struct TestView: View {
var d: GridData
@Binding var list: [GridData]
@State private var dragOver = false
var body: some View {
VStack {
Text(String(d.id))
.font(.headline)
.foregroundColor(.white)
}
.frame(width: 160, height: 240)
.background(colorPalette[d.id])
.onDrag {
let item = NSItemProvider(object: String(d.id) as NSString)
item.suggestedName = String(d.id)
return item
}
.onDrop(of: [UTType.text], isTargeted: $dragOver) { providers in
return true
}
.border(Color(UIColor.label), width: dragOver ? 8 : 0)
}
}
}
Run Code Online (Sandbox Code Playgroud)
Asp*_*eri 16
它由DropProposal放置操作管理,默认情况下(如果您不提供显式放置委托).copy如文档所述,添加“+”符号。通过此您可以通知用户某些内容将被复制。
/// Tells the delegate that a validated drop moved inside the modified view.
///
/// Use this method to return a drop proposal containing the operation the
/// delegate intends to perform at the drop ``DropInfo/location``. The
/// default implementation of this method returns `nil`, which tells the
/// drop to use the last valid returned value or else
/// ``DropOperation/copy``.
public func dropUpdated(info: DropInfo) -> DropProposal?
Run Code Online (Sandbox Code Playgroud)
如果您想显式管理它,请为 DropDelegate 提供已实现的放置更新,如下面的演示所示
func dropUpdated(info: DropInfo) -> DropProposal?
// By this you inform user that something will be just relocated
return DropProposal(operation: .move)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1982 次 |
| 最近记录: |