Search code examples
macoscocoanswindow

There is a strange phenomenon in NSWindow's Autosave


After I set the saved name, the save is valid, but it does not mean my last actual size.

After my observation, I found that the height of the open NSWindow is smaller than that of the last one. It's about title's height.

This may have something to do with my setup, but I don't know how to improve it. So that the size and location of the storage is exactly the same as the last time.

    override func windowDidLoad() {
    super.windowDidLoad();
    self.windowFrameAutosaveName = NSWindow.FrameAutosaveName(rawValue: "MainAppWindowAutosave");
    self.window?.titleVisibility = .hidden
    self.window?.isMovableByWindowBackground = true;
    self.window?.titlebarAppearsTransparent = true
    self.window?.styleMask = [.fullSizeContentView,.titled,.resizable,.miniaturizable,.closable]
    self.window?.toolbar?.isVisible = false;
}

Solution

  • windowFrameAutosaveName sets the height. titleVisibility and toolbar.isVisible can change the height. Set windowFrameAutosaveName after titleVisibility and toolbar.isVisible.