Search code examples
macoscocoaautolayoutnssplitview

Pushing sub-view of NSSplitView when constraint reached


In OS X, I have a NSSplitView with 3 subviews stacked vertically: A, B, C.

View B has a minimum height constraint. If I push the B-C divider upwards, it stops when the constraint is reached, as it should.

I would like, however, to have divider A-B push upwards as well, when the min. height constraint of B is reached (and there is no other constraint in A).

Conversely, if there is a max. height constraint in B and I pull the B-C divider downwards, I'd like divider A-B to follow (other constraints permitting).

Is there any way to achieve this with AutoLayout? If not, could you suggest an approach/point to a relevant resource?

Thanks.


Solution

  • If you look at the constraints that are added to the SplitView during the drag, you'll notice that NSSplitView adds Required constraints that keep the non-divider-neighboring views in their current position.

    "<NSLayoutConstraint:0x6100000827b0 H:|-(512.5)-[View3]   (Names: View3:0x600000120500, '|':MySplitView:0x6000001203c0 )>"
    

    At the end of the drag these get removed.

    If these constraints were not added or just added at a lower priority, you would get the behavior you described. And unfortunately, since they're Required, there isn't even a recommendable workaround (such as manually adding an even higher priority constraint).


    You could file an enhancement request to have NSSplitView offer more control over these constraints.