1

I'm trying to understand how splitview works.

I have this simple split view layout.

enter image description here

and the button action methods:

@IBAction func hideYellow(sender: NSButton){
    splitV.arrangedSubviews[0].isHidden = !splitV.arrangedSubviews[0].isHidden
    splitV.adjustSubviews()
}

@IBAction func hideGreen(sender: NSButton){
    splitV.arrangedSubviews[1].isHidden = !splitV.arrangedSubviews[1].isHidden
    splitV.adjustSubviews()
}

It works when the buttons are clicked, but the during this process the size of subviews are changed.

Here are the screnshots of hiding/unhiding yellow view for 4 times.

1st time:

enter image description here

As you noticed, the yellow view size is changed.

2nd time:

enter image description here

3rd time:

enter image description here

4th time:

enter image description here

So more time you repeat this, theyellow view gets smaller and smaller.

The splitview in xib:

enter image description here

I tried giving width constraint to white view, to stop yellow view from getting smaller during this process. Still it didnt respect the wdith constraint of white view.

I also unchecked the autoresize subviews option for yellow view.

Please let me know what mistake I did.

Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109

1 Answers1

1

This only worked if I set the frame to a fixed position.

Initially I had to set the divider poisiton

splitV.setPosition(300, ofDividerAt: 0)

and manually update the subview width

@IBAction func hideYellow(sender: NSButton){
    collapsed = !collapsed
    if collapsed{
        splitV.subviews[0].setFrameSize(NSSize(width: 0, height: view.frame.height))
    }else{
        splitV.subviews[0].setFrameSize(NSSize(width: 300, height: view.frame.height))
    }
    splitV.adjustSubviews()
}
Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109