Create a new file that inherits from the Nswindowcontroller class Windowcontroller.
Select class:
Write code in Windowcontroller.swift.
Add the code inside the Windowdidload:
If let window = window, screen = window.screen {let offsetfromleftofscreen:cgfloat = Offsetfromtopofscree N:cgfloat = Screenrect = screen.visibleframe print (screenrect) let neworiginy = Cgrectgetmaxy ( Screenrect)-Window.frame.height-offsetfromtopofscreen //Set window lower left corner coordinates window.setframeorigin (nspoint (x: Offsetfromleftofscreen, Y:neworiginy) }
Running we can see:
There's another one.
We can see that screenrect is the screen size!
Then there is a problem, the new window will be completely overlapping with the original window, this is very unfriendly, how to solve it?
Adding a piece of code is OK:
Required init? (Coder:nscoder) { super.init (coder:coder) //Set new window pop-up waterfall Shouldcascadewindows = True }
Run it again to see:
[Macos]init Windows position--Method Two: Code implementation