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?
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)
}
I met the same issue, but I solved it calling setPosition from viewDidAppear. Hope this helps.
- (void)viewDidAppear {
[self.splitView setPosition:300 ofDividerAtIndex:0];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With