JLNDragEffectManager is a small, simple Objective-C class for Cocoa that gives you the morphing animation as seen when dragging controls from the palette in Interface Builder 3.
I wrote a post titled “Your Very Own Drag Show with JLNDragEffectManager” with a full explanation of the design decisions, goals, and a basic video demonstration.
- Download the source and demo project below.
- Add JLNDragEffectManager to your project.
- Add the QuartzCore to your project’s linked frameworks.
- Remember to include JLNDragEffectManager.h.
- Override the three view dragging methods.
The code below shows how to use this effect manager in your custom view. The three main drag-and-drop methods are overridden to call the manager’s corresponding methods.
// Let's figure out our geometry. For shits-n-giggles, we'll
// make the whole window our source screen rect, and the
// current mouse position (at start of drag) as the slide-back point
NSPoint startPointInScreen = [NSEvent mouseLocation];
NSRect sourceScreenRect = [[self window] frame];
// Let’s use some images reminiscent of Interface Builder’s
// drag-from-Library-palette-to-make-a-real-object effect
NSImage * insideImage = [NSImage imageNamed:@"textfieldasicon"];
NSImage * outsideImage = [NSImage imageNamed:@"textfieldrealized"];
// Don the boas and start the drag show!
- (void)draggedImage:(NSImage *)draggedImage movedTo:(NSPoint)screenPoint
// Update the position
[[JLNDragEffectManager sharedDragEffectManager] updatePosition];
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint
// End the drag show, clean up the glitter and sweat-and-masquera
// puddles and call it a day
// Do any other processing you might need, including going home to
// your cats and wig collection
This source code is free to use in any private, public, or commercial software products, with attribution. See the full license included with the source code.
Source & Demo
Projects in Which JLNDragEffectManager is Used
- XTabulator by Yours Truly
- SPICE 5 by Yours Truly
- FakeApp by Todd Ditchendorf
- Papers 2 by Mekentosj
- Raskin for Mac
Use the drag effect manager in your app? Let me know and I’ll post a link.