How to set the position and size (software) for the main window?

I am using the latest default project for OS X (10.11, Xcode 7.0). It uses storyboards, and the hierarchy looks like this:

Window Controller -> View Controller

I want to set the initial position and frame size for the window. Obviously, the user can change this, but I want it to start with some default values. I have tried subclassing NSWindowController, but this has no effect.

  class WindowController: NSWindowController {

     override func windowDidLoad() {
        super.windowDidLoad()

        guard let window = window else {
           return
        }

        let windowOriginPoint = CGPoint(x: 0, y: 0)
        let windowSize = CGSize(width: 800, height: 400)
        window.setFrame(NSRect(origin: windowOriginPoint, size: windowSize), display: true)

        print("windowDidLoad")
     }

  }

What is the right way to do this?

+4
source share
1 answer

. , setFrame windowDidBecomeMain windowDidLoad; , , : . , : windowController

private var firstAppearance = true;

windowDidBecomeMain setFrame firstAppearance; firstAppearance false.

+2

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


All Articles