问题
How can I set the start position of a NSSplitView?
The closest thing I've found that looks like it would work is setPosition
//Set splitView position.
[splitView setPosition:330 ofDividerAtIndex:0];
This doesn't seem to do anything though, my splitview still starts with the divider in the center.
ANy ideas?
回答1:
Maybe that is the center? If splitView is correctly hooked up to your split view, that code should work. You should probably log [splitView minPossiblePositionOfDividerAtIndex:0] and [splitView maxPossiblePositionOfDividerAtIndex:0] before trying to set the position of the divider so you know the possible values.
回答2:
You don't set the position of the divider, you set the sizes of your NSSplitView's subviews. The divider is then repositioned automatically.
This is how I positioned my divider and subview size (in swift):
let subview: NSView = mySplitView.subviews[1] as NSView
subview.setFrameSize(NSMakeSize(subview.frame.size.width, 100))
回答3:
NSSplitView
needs initial non-sized bounds to make them layout correctly.
If your view has zero-size, then it will not show expected layout.
The best way is providing non-zero layout (this is what IB does), but sometimes this is impossible.
If you cannot provide non-zero size, then I think you have to provide proper - (void)splitView:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize
delegate method implementation to layout everything manually yourself. (this is my current best practice)
回答4:
In the view's class housing the split view
override func viewWillAppear() {
self.mySplitView.setPosition(120, ofDividerAtIndex: 0)
}
or wherever you want it to start.
来源:https://stackoverflow.com/questions/11995073/starting-position-of-nssplitview-divider