1

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.

WoffOVkee
  • 435
  • 3
  • 16
  • Your question is kind of confusing. Do you have some code to help us know what you've tried? –  Mar 02 '17 at 01:48
  • cause en is not my first language ... so I put my drawing. :) sorry about your inconvenience – WoffOVkee Mar 02 '17 at 02:07
  • That's ok, no offense intended. Let's get constructive... (1) You are talking about dragging an image and leaving a "blank spot" behind - what do you mean? Usually "dragging" implies "moving" or "relocating". Are you wanting to "copy" the image to a second location? (2) The other point of confusion is your mention of a "collection view". Are these images in a UICollectionView? Are you trying to reorder cells in a collection view? (3) EDIT: I just realized you tried to attach an image - it didn't work. –  Mar 02 '17 at 02:11
  • (1) I'm dragging Custom Class that is subclass of NSCollectionViewItem. While dragging, the item disappears from NSCollectionView (I know item is there. It just look like disappear. and the space in NSCollectionView become 'WHITE BLANK SPACE'.) and attached beside mouse cursor. (2) I'm making a macOS app. It's NSCollectionView. THAT 'white blank space' is what I want to fix. I want to make that space 'showing it's contents (not white space)' while dragging. plus for (1) all is about 'while dragging'. when drag has done, items are copied or moved with out any problem. – WoffOVkee Mar 02 '17 at 02:23
  • 1
    ok. I get a hint. When I wrote 'I know item is there. It just .....', I thought what if I just call 'reloadData' from 'beginDraggingSession(with:event:source:)'. It will be draw all Items again include items which are dragging, I hope. and it seems to work. ( and I need to make sure there is no side-effect.) – WoffOVkee Mar 02 '17 at 02:36
  • @WoffOVkee Did you find a solution? I tried calling reloadData, and it seems to do the trick but then I get some other unexpected behavior – Wes Aug 13 '19 at 12:41
  • 1
    @Wes i update my solution and hope this solution can help you. – WoffOVkee Aug 19 '19 at 08:33
  • @WoffOVkee Thanks for the reply. Would you mind sharing some code? I have been trying to do this for hours and all I'm able to do is change the image being dragged. Thanks! – Wes Aug 20 '19 at 13:34
  • @Wes I update my question again. – WoffOVkee Aug 28 '19 at 05:13

0 Answers0