Search code examples
macoscocoansstoryboard

Gap in height between NSSplitView and its superview - where is it coming from?


I am using Storyboards to build an OS X app. It is arranged such that my main window controller contains as its content view controller an NSSplitViewController.

Sometimes, however, when I open up the app, there is a gap between the top of the split view and the bottom of the window's title bar:

app with gap

This gap goes away as soon as I resize the window.

I captured the view hierarchy and I saw these auto layout constraints. One in particular looked interesting:

view debugger

Interesting! But I cannot find any place in my app that specifies these auto layout constraints, neither in the window nor the split view.

Once the window resizes, the constraint looks like this (this is on the NSThemeFrame):

enter image description here

The constraint isn't grayed out if I look at it from the NSSplitView:

enter image description here

The difference of 22 makes some sense; that's the height of the title bar itself.

What can I do to find out what's making it behave like this?


Solution

  • The issue ended up being that I needed to start from the inside out. First, I checked the dimensions I specified on the frame for each of the views of the NSSplitView. Once I got those dimensions, I then went to the NSSplitView's frame and set the dimensions accordingly.

    Then, I went to the NSWindow's frame and ensured that its dimensions were at least as big as the dimensions of the NSSplitView. If it's bigger, no problem, but if it's smaller, then the window opens up cut off.

    This may be just specific to my use case because I tried creating a new project and reproducing the issue, but wasn't able to reproduce it.