如何解决为什么我的视图的右上角有一个“加号”图标?
我正在尝试将拖放功能实现到我的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)
}
}
}
解决方法
它由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?
如果您想对其进行显式管理,则向DropDelegate提供已实现的drop update,如下面的演示中所示
func dropUpdated(info: DropInfo) -> DropProposal?
// By this you inform user that something will be just relocated
return DropProposal(operation: .move)
}
,
这是正常的用户界面,指示在此时手指所处的位置,可以拖放要拖动的视图。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。