Saturday, February 5, 2011

How to build a drop copy like app? (objective-c)

Few things,
1. Drop copy is transparent
2. It is fixed to the desktop (F11 will not hide it)
3. It accepts drag and drop
4. Cool animation

Making your window transparent
You can make your window transparent by using a subclass of NSWindow and including the code below.

- (id) initWithContentRect: (NSRect) contentRect
styleMask: (unsigned int) aStyle
backing: (NSBackingStoreType) bufferingType
defer: (BOOL) flag
if (![super initWithContentRect: contentRect
styleMask: NSBorderlessWindowMask
backing: bufferingType
defer: flag]) return nil;
[self setBackgroundColor: [NSColor clearColor]];
[self setOpaque:NO];

return self;

Fixing the app to the desktop
Drop copy app stays fixed to the desktop. At a glance it is more like a desktop icon where we could drag and drop files into. This is how we could make our app work like that.

1. Include the code below in the above function

[self setCollectionBehavior:NSWindowCollectionBehaviorStationary];

2. Make the app background only from the .plist file

Making the app accept drag and drop
I have explained it in one of my previous posts. Please do have a look :)

Multiple Drop - Objective C Sample Code

Cool animation
The simplest way to achieve this would be to use a .gif in an image view but you could also try using a web view or core animations in objective c.

No comments: