Create a new window with NSWindow

I would like to create a new window programmatically. I have the following code and it builds, but my window does not appear. The only way to make this visible is to add it as a child window to the default window. How can I make win independent?

@IBOutlet var window: NSWindow func applicationDidFinishLaunching(aNotification: NSNotification?) { var win = NSWindow(contentRect: NSMakeRect(100, 100, 600, 200), styleMask: NSResizableWindowMask, backing: NSBackingStoreType.Buffered, defer: true) window.addChildWindow(win, ordered:NSWindowOrderingMode.Above) } 
+6
source share
2 answers

How about adding:

 win.makeKeyAndOrderFront(win) 

For me OSX (not iOS) using Swift and writing to vim

 let win = NSWindow(contentRect: NSMakeRect(100, 100, 600, 200), styleMask: NSResizableWindowMask, backing: NSBackingStoreType.buffered, defer: true) win.makeKeyAndOrderFront(win) 

a window pops up

+5
source

You will also need an NSWindowController to display the window:

 let window = NSWindow(...) let controller = NSWindowController(window: window) controller.showWindow(self) 
+2
source

Source: https://habr.com/ru/post/970406/


All Articles