Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSSplitView initial divider position?

I have an NSSplitView that uses autolayout to position the two subviews inside of it.

Everything works great, but I want to set the initial position of the divider to a constant value (300 pixels) for aesthetic reasons. I'm not using interface builder.

If I do [_splitView setPosition:300 ofDividerAtIndex:0];, I see no effect, same thing if I add a [_splitView adjustSubviews] call right after that.

Any tips?

like image 886
user358829 Avatar asked Jan 24 '14 23:01

user358829


2 Answers

I met the same issue. It seems that setPosition has no effect if invoked right after you add subviews to the splitView.

I solve the problem by waiting a little while before invoking setPosition. Here is the sample code in swift:

func delay(delay:Double, closure:()->()) {
    let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC)))
    dispatch_after(time, dispatch_get_main_queue(), closure)
}

delay(0.05) {
    splitView.setPosition(300, ofDividerAtIndex: 0)
}
like image 72
Tyler Liu Avatar answered Oct 16 '22 21:10

Tyler Liu


I met the same issue, but I solved it calling setPosition from viewDidAppear. Hope this helps.

- (void)viewDidAppear {
  [self.splitView setPosition:300 ofDividerAtIndex:0];
}
like image 24
Antonio J. Avatar answered Oct 16 '22 21:10

Antonio J.