Keep NSWindow front

user661577 picture user661577 · Mar 19, 2011 · Viewed 12.8k times · Source

I open a NSWindow from my main NSWindow.

DropHereWindowController *dropHereWindowController = [[DropHereWindowController alloc] initWithWindowNibName:@"DropHereWindow"];
[dropHereWindowController showWindow:nil];

I want this window to stay on top of my main window when dragging a file from the finder to that "DropHereWindow". However when opening the finder (not having the focus any longer) my "DropHereWindow" goes behind my main window.

I tried orderFront, makeKey, makeKeyAndFront but nothing helped. What can I do about it?

Answer

Anne picture Anne · Mar 19, 2011

Method:

- (void)setLevel:(NSInteger)windowLevel

Sub-class the NSWindow:

[self setLevel: NSStatusWindowLevel];

Or simply use:

[window setLevel: NSStatusWindowLevel];

Available levels:

  • NSNormalWindowLevel
  • NSFloatingWindowLevel
  • NSSubmenuWindowLevel
  • NSTornOffMenuWindowLevel
  • NSModalPanelWindowLevel
  • NSMainMenuWindowLevel
  • NSStatusWindowLevel
  • NSPopUpMenuWindowLevel
  • NSScreenSaverWindowLevel
  • kCGDesktopWindowLevel