1
votes

When I create a new document based project with storyboard in Xcode and run it, the new window gets positioned somewhere at the lower half of the screen.

That's because the Initial Position is set to that screen location with proportional relations.

Now, I rather want my windows to start at the top left, e.g. at a fixed position 20x20 off the left of the menu bar. The settings in Interface Builder do not provide for that, it seems. It's either relative (then the position changes depending on the screen size) or absolute but with no way to define the distance from the top of the screen to the top of the window.

Plus, I still need to cascade new windows, i.e. not set every new window to 20x20, but have further ones cascaded.

1
Looks like a bug to me.Willeke

1 Answers

1
votes
  1. Make a subclass of NSWindowController and assign that as the Window Controller in IB.

  2. In this subclass, overwrite windowDidLoad:

- (void)windowDidLoad {
    [super windowDidLoad];

    self.shouldCascadeWindows = YES;

    // Position at top left corner of main screen
    NSWindow *w = self.window;
    NSPoint pos = NSMakePoint (20, 40); // this is where the 1st window appears
    pos.y = NSScreen.mainScreen.frame.size.height - w.frame.size.height - pos.y;
    [w setFrame:CGRectMake(pos.x, pos.y, w.frame.size.width , w.frame.size.height) display:NO];
}