So I want to drag an object from one source to multiple potential destinations. When the object is over each destination, I want it to 'morph' into a different image. Is there a straightforward way to do this from the NSDragSource perspective?
The image link is inserted in the HTML page using <img> src attribute. Whenever we are going to insert the image, we have to enable draggable=”true”. Also, enable ondragstart=”drag(event)” so that this image can be draggable along with setting the image width and height.
To move an object, place the mouse cursor over it, press and hold down the left mouse button, then move the mouse while still holding down the left mouse button. When you have "dragged" the object to the location you want, let go of the mouse button.
You can do so by using enumerateDraggingItemsWithOptions:
method of NSDraggingInfo
in your dragging destination's handler methods (i.e. - your implementation of NSDraggingDestination
protocol).
For example:
- (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender
{
NSImage* newDragImage = <take it from wherever>;
[sender enumerateDraggingItemsWithOptions:0
forView:sender.draggingSource
classes:[NSArray arrayWithObject:[NSPasteboardItem class]]
searchOptions:nil
usingBlock:^(NSDraggingItem *draggingItem, NSInteger idx, BOOL *stop) {
NSRect theFrame = draggingItem.draggingFrame;
theFrame.size = newDragImage.size;
[draggingItem setDraggingFrame:theFrame contents:newDragImage];
*stop = NO;
}];
}
Joshua Nozzi has posted a great way to do this: http://joshua.nozzi.name/2009/10/jlndrageffectmanager/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With