How to Bring Nswindow to Front and to the Current Space

How to bring NSWindow to front and to the current Space?

To bring your app to the front:

[NSApp activateIgnoringOtherApps:YES];

Swift:

NSApp.activateIgnoringOtherApps(true)

Swift 3:

NSApp.activate(ignoringOtherApps: true)

Other window comes to front when bring window to front

Turns out the issue is related to this other question. An important piece I failed to mention here is that the windows in my app that exhibited this issue were titlebar-less.

By default, when you have a titlebar-less window, Cocoa doesn't allow it to become the main window. I subclassed NSWindow and overrode canBecomeMainWindow to return YES at all times and this solved my problem.

This also explained why my windows were resizable but the resize handles never showed up on their own; only main windows get resize handles!

Make NSWindow Front But Not In Focus

Instead of makeKeyAndOrderFront:, try just orderFront: (docs)

How to bring all the app's windows to front when making active just one?

This code does the trick for me:

-(void) applicationDidBecomeActive:(NSNotification *)notification
{
// TODO: go over windows here and bring them active
for (NSWindow * window in [NSApp orderedWindows]) {
[window orderFrontRegardless];
}
}

don't forget to set up the file to be the app's delegate in order for this code to work.

How do I make an NSView move to the front of all NSViews

Use makeKeyAndOrderFront:, perhaps?



Related Topics



Leave a reply



Submit