davis
davis

Reputation: 1951

Setting initial position of NSWindow only works the first time

I'm trying to set my NSWindow to be in the center of the screen, but I'm noticing that when I quit and reopen the app, it takes the position that the window was in when the app closed. Is this expected behavior?

Upvotes: 2

Views: 839

Answers (1)

Marek H
Marek H

Reputation: 5576

If you selected "Restorable" window behaviour then it's the correct behaviour. Restorable

You can disable this by behaviour by unchecking restorable and also leave your autosave name empty.

Your application saves the state into "~/Library/Saved Application State/com.identifier.appName.savedState" folder and loads on launch Saved app state

Also one hidden hack to help:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  [[NSUserDefaults standardUserDefaults] setObject:@NO forKey:@"NSQuitAlwaysKeepsWindows"];
}

Upvotes: 5

Related Questions