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
How to Make Swiftui Listmenu with Different Behaviors
Programatic Constraints Not Obeyed
Pattern Match and Conditionally Bind in a Single Switch Statement
Binding in a Foreach in Swiftui
When Calling a Function in Swift, What Does Each Part Mean
Xcode & Swift - Window Without Title Bar But with Close, Minimize and Resize Buttons
Nothing Prints Out in the Console in Command Line Tool Xcode
Get Fullpath or Convert to Fullpath
Create an Outlet in Storyboard to an Inherited Property
How to Send Push Notifications Without Using Firebase Console
Opposite of _Conversion in Swift to Assign to a Value of a Different Type
Swiftui Present Alert with Input Field
Swift Performseguewithidentifier Shows Black Screen
Physics Detecting Collision Multiple Times
\N in the End of Line with Using Print
In Swift, How to Write a Generic Function to Resize an Array
Macos Command Line Tool with Swift Cocoa Framework: Library Not Loaded