Trouble With NSSplitView Starting Sizes (Storyboar

2019-02-05 09:23发布

问题:

I just started a simple Cocoa app using Swift, Storyboards, and a Document.

The only change I've made is to replace the default View Controller in Main.storyboard with a Split View Controller. Everything works great as far as the subviews populating correctly except for one thing: the divider is always at the far left of the window when I start the app. This is with a vertical Split View. (If I change to horizontal the divider starts at the very top.)

I have tried adding constraints but IB won't even allow me to add constraints to anything except content within the subviews.

I've also tried using splitView.setPosition ofDividerAtIndex but had no success.

How can I specify either the width of the left subview or the position of the divider?

回答1:

The initial size of the split view is based on the constraints. If there are no constraints to satisfy then the width or height is 0. You are correct, you can't add any constraints to the root view. You have to add subviews that have constraints that imply the desired height or width.

This could simply be a NSView with a set width or height constraint.