NSDraggingSession distorts the images I give it

Graham Cox

I’m modernising some old code that does drag and drop the old, simple and perfectly functional (but deprecated) way.

The new way seems twice as complicated to me, but hey-ho.

Anyway, I’m creating NSDraggingItems for each item to be dragged, and I’m setting the image and frame to sane values. When I start to drag the items however, the images are slightly resized - they expand widthways a small amount, but vertically a somewhat larger amount, making each item appear to stretch vertically. It looks like crap.

The images are actually square - and I set the image size to match the frame size, which has the same width and height.

for( DKOLibraryItem* libItem in itemsToDrag )
NSDraggingItem* dragItem = [[NSDraggingItem alloc] initWithPasteboardWriter:libItem];
NSRect libItemRect = [dv imageRectForItemAtIndex:dragItemIndex]; // this rect is square, width = height

NSImage* icon = [libItem.previewImage copy];
icon.size = libItemRect.size;

[dragItem setDraggingFrame:libItemRect contents:icon];
[icon release];

//…. other stuff

Has anyone some clue what’s going on here?


Join cocoa@apple-dev.groups.io to automatically receive all group messages.