Vicenç Gascó
Vicenç Gascó

Reputation: 1346

NSWindow like Quicksilver

I am creating an app, where I want to show a "pop-up" or "notification" to the user when he press a hotkey.

I want that to be displayed as a floating message, like the one that appears when you change the volume, or the brightness, or like the Quicksilver App input window.

I want it to has alpha, to fade in, to stay there for 5-8 secs, and to fade out.

And ... the problem is that I don't know how to get started on that. I've tried:

NSRect frame = NSMakeRect(0, 0, 600, 65);
_myWindow = [[NSWindow alloc] initWithContentRect:frame
                 styleMask:NSBorderlessWindowMask
                 backing:NSBackingStoreBuffered
                 defer:NO];
[_myWindow setBackgroundColor:[NSColor blueColor]];
[_myWindow center];
[_myWindow makeKeyAndOrderFront:NSApp];

But, of course that's not what I'm trying to do.

Any help is welcome ;-)

Upvotes: 2

Views: 640

Answers (1)

sbooth
sbooth

Reputation: 16986

I believe the proper term for this is a bezel window. Quicksilver is open source (https://github.com/quicksilver/Quicksilver) so you can see how they do it, but I've accomplished something similar with a custom NSWindow subclass:

- (id) initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag
{
    if((self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:bufferingType defer:flag])) {
        [self setOpaque:NO];
        [self setIgnoresMouseEvents:YES];
        [self setLevel:NSFloatingWindowLevel];
        [self setBackgroundColor:[NSColor clearColor]];
    }

    return self;
}

and the animation controlled by the window controller:

- (void) windowDidLoad
{
    CAAnimation *animation = [CABasicAnimation animation];
    [animation setDelegate:self];
    [[self window] setAnimations:[NSDictionary dictionaryWithObject:animation forKey:@"alphaValue"]];
}

to make the window fade in, code similar to the following should work:

[[self window] setAlphaValue:0.0];
[[[self window] animator] setAlphaValue:1.0];

[[self window] orderFront:self];

I realize this isn't a plug and play solution but it should get you started.

Upvotes: 7

Related Questions