Want dragging left its item where it is while dragging

376 Views Asked by At

I made custom dragging image and currently using it.

a problem is when I drag items item's origin places become a blank space.

I want to left original image(?) where it's origin.

So my collection view look like nothing happened. (Of course, there are custom images under mouse pointer which is dragging.)

please give me a hint.

thank you.

It is hard to explain through text so I draw a picture XD

customImage

Update my solution

  1. inherit NSCollectionView for overrideing func beginDraggingSession(with items: [NSDraggingItem], event: NSEvent, source: NSDraggingSource) -> NSDraggingSession
  2. get selected indexex
  3. while loopping selected indexes, make NSDraggingItem and replace item's, which is from method's arg, content at the index. At this point, if you make an image and set it using setDraggingFrame dragging, image under mouse pointer will be your image (I didn't test another ways) and collectionView will be there as same as before dragging.

Update 2

I read code again and found solution is simple actually. (but I don't think it is recommendable solution...)

override func beginDraggingSession(with items: [NSDraggingItem], event: NSEvent, source: NSDraggingSource) -> NSDraggingSession {
    //...
    // reload your table data again here
    return super.beginDraggingSession(with: newItems, event: event, source: source)
}

and you need to calculate what itmes need to be removed and gone by yourself.

0

There are 0 best solutions below