1 year ago

#321243

test-img

Simon Degn

NSWindow does not center by storyboard settings or programmatically

I have made an MacOS application with two windows. The first one is a fixed loading window, that only appear for a few seconds while loading the content for the main window.

The loading window is a small 400x300px window with no title bar, control buttons or anything. This window should be centered on the screen, but for some unknown reason this won't work for me. It always ends up an position where it's centered on the y-axis but too much to the left on the x-axis.

I have tried centering the window both with storyboard properties and programmatically.

Here's my storyboard settings:

enter image description here

enter image description here

And the code used for the window is called inside the viewDidLoad of the contentViewController for the window:

 NSApp.activate(ignoringOtherApps: true)
 NSApp.windows.first?.orderFrontRegardless()
 NSApp.windows.first?.center()

swift

nswindow

0 Answers

Your Answer

Accepted video resources