DragDropDemo
DragDropDemo copied to clipboard
Dragged image from app does not resize properly
The dragged item has the same size as the entire app window rather than the image being dragged.
It appears your code is supposed to resize if the item if from the app's window:
/* Only resize a fragging item if it originated from one of our windows. To do this,
* we declare a custom UTI that will only be assigned to dragging items we created. Here
* we check if the dragging item can represent our custom UTI. If it can't we stop. */
if ( ![[[draggingItem item] types] containsObject:kPrivateDragUTI] ) {
NSLog(@"The fragging item did NOT originate from our window!");
*stop = YES;
} else {
/* In order for the dragging item to actually resize, we have to reset its contents.
* The frame is going to be the destination view's bounds. (Coordinates are local
* to the destination view here).
* For the contents, we'll grab the old contents and use those again. If you wanted
* to perform other modifications in addition to the resize you could do that here. */
NSLog(@"The fragging item originated from our window!");
[draggingItem setDraggingFrame:self.bounds contents:[[[draggingItem imageComponents] objectAtIndex:0] contents]];
}
I added the NSLog statements to test whether the resize was attempted. If I'm reading the code correctly, items dragged form the app should invoke the resize. What I see happen with an ordinary JPG file is the IF block runs when an image dragged into the app (as expected), but the ELSEblock does not appear to run if the image is dragged out to the finder.
I'm perplexed as one or the other should always run but the NSLog statement in the ELSE block doesn't execute in either scenario. It appears the whole IF ELSE statement is not run on drag from the app.
I must have been pretty tired last night when I wrote the first comment. The IF ELSE statement is in the draggingEntered method. Of course the dragged item did not originate for the app window unless perhaps it was dragged out and then dragged back.
However a continuous drag operation from the app — even switching back and forth between active apps — doesn't call this method. I'm confused why this code is here. Perhaps it handles a bug in some earlier OS version? Testing on 10.11.1 and I don't see where the ELSE block would ever be used.
The code I was looking for was in was obviously in dragImage. I can see where the it creates the semi-tranparent image for the drag proxy. I just need to figure out how to get the scaled image size inside the view.