Reputation: 33101
It is hard to put this problem into words, but a real world example will help. If you look at the iTunes app, it appears to have a NSSplitView
for the Sidebar | Content
split, and a nested NSSplitView
for the source list and artwork panel.
======>
When you drag the divider to make the sidebar thinner, the artwork view (the bottom half of the inner NSSplitView
) shortens to maintain the right aspect ratio. This is the behavior I am after.
I have hooked up the outer NSSplitView
's delegate
to point to the sideBarController so I can get the sizing changes and resize the lower portion of the split view programatically. I have this half of the problem working correctly, that is, when I change the sidebars, width, the sidebar panels adjust their size accordingly.
The problem I am having issues in attacking is how to resize the sidebar width when the nested NSSplitView
's height is altered. I originally tried to find ways to make this inner splitview's divider non-draggable, but could not find any way to do that. The way I have it setup now is to set the inner scrollview's delegate to be the windowController that owns the main splitview, then do a calculation on the height to alter the width of the info panel.
Of course, altering ones size causes the other splitview to alter its size, which aters the originals size again and a endless loop is created. I could add flags and timers to try and work this out, but already it seems like I am going agains the grain here to achieve this functionality.
How can I properly constrain the nested splitview panel to its parents width or more generally, What is the best way to duplicate the resizing behaviors of the iTunes "Selected Item / Now Playing" view?
Upvotes: 2
Views: 2199
Reputation: 243156
You might try taking a look at my CHLayoutManager, which would allow you to do:
[mySplitView setLayoutName:@"splitview"];
CHLayoutConstraint *constraint = [CHLayoutConstraint constraintWithAttribute: CHLayoutConstraintAttributeHeight relativeTo:@"splitview" attribute: CHLayoutConstraintAttributeWidth];
[mySplitView addConstraint:constraint];
Now whenever your mySplitView
resizes, it will automatically update the height of the view to match the width.
You may have to do something a bit more complex for your situation, but this is the general idea.
Upvotes: 3