I want to close my object-menu as soon as my finger crosses the border of the view when dragging an item. CARE: I do not want to close the item when dropping the item. Unfortunately I have no idea on how to achieve this.
I am simply using:
struct BuildingItemSlot: View {
var preview: ObjectPreview
var body: some View {
VStack() {
Image(uiImage: UIImage(contentsOfFile: preview.dataPath + "/Raw/Thumbnails/" + preview.id + ".png") ?? UIImage())
.resizable()
//.scaledToFit()
.frame(width: 64, height: 64)
.padding(4)
//.border(Color.black, width: 1)
}
.onDrag({ NSItemProvider() })
}
}
embedded in a view that makes up the inventory ...
VStack() {
ForEach(networkManager.objectPreviewList.objects ?? []){ preview in
BuildingItemSlot(preview: preview)
}
}
.padding(40)
I am opening and closing the side menu simply by with:
.offset(x: stateHandler.openBuildingsMenu ? 0 : 480)
Thanks a lot, Jakob
onDrop(of:delegate)
is the view modifier to be used on the view which can accept a drop.dropEntered
, dropExited
, dropUpdated
, validateDrop
- You can dynamically validate if drop is valid or not performDrop
validateDrop
should give you control when to accept / deny drop dynamically.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.