Starting Position of NSSplitView divider

邮差的信 提交于 2019-12-06 18:54:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!