tuna
tuna

Reputation: 931

Show up a custom UI somewhere on screen

I've programmed a custom UI which looks like this: http://www.youtube.com/watch?v=XLsrVVhEs94

Currently it is only working within a NSView itself but I want it to show up in every corner of my screen.

So I programmatically created an NSWindow like so [[NSWindow alloc] initWithContentRect:windowRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];

This works great but there is a problem: Every time I open this UI I can barley see that the NSWindow was just created. I can see a shadow that has the size of the NSWindow and after that it disappears (because of [NSColor clearColor]). I think that [NSColor clearColor] applies too slow to the just created NSWindow.

The NSWindow was set up with [window setOpaque:NO] so it is transparent.

Is there another way to display a custom UI somewhere on my screen?

- Timo

Upvotes: 0

Views: 77

Answers (1)

Ryan Nichols
Ryan Nichols

Reputation: 308

I think you want to set the defer to YES. Referring to the documentation, the defer property will either create the window immediately, or defer it until it is displayed on the screen. In this case you can then set all the window properties, add subviews, etc before showing on the screen.

NSWindow *myWin = [[NSWindow alloc] initWithContentRect:windowRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
... do window setup here ...
[myWin orderFront:self];

Additionally if that still flickers, you can call 'display' on the window so it draws all the subviews into it's buffer first (including your clear), then call orderFront.

Upvotes: 2

Related Questions