2

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.

enter image description here ======> enter image description here

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?

coneybeare
  • 33,113
  • 21
  • 131
  • 183

1 Answers1

3

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.

Dave DeLong
  • 242,470
  • 58
  • 448
  • 498
  • Thanks for the answer. This would take care of half the problem easily, but what happens when the user resizes the inner view, I would have to resize the outer view and get constraint cycles where I would have to have funky logic between two view controllers to ensure this doesnt happen. Is there no way around this behavior? If I could disable manual resizing of the inner split view, your solution would work amazingly – coneybeare Jan 27 '11 at 03:09
  • @coneybeare it's probably possible; it would depend on how your views are nested and whatnot. However, CHLayoutManager doesn't do constraint cycles. Each view is processed once per change notification, and the constraints are processed in the order they're added. – Dave DeLong Jan 27 '11 at 03:24
  • Dave, your CHLayoutManager works great. I ended up removing my sidebar splitview completely and use two nsviews instead. The bottom one is managed using CHLayoutManager, and I am now just trying to figure out how to make the source list shrink in height as the artwork panel grows. – coneybeare Jan 27 '11 at 05:05
  • @coneybeare There are ways CHLayoutManager could handle that too, but it'd require a bit more custom code. Shoot me an email and I'll help you work it out. – Dave DeLong Jan 27 '11 at 05:33
  • What is about NSLayoutConstraint, is it not able to handle this? – Stephan Jul 14 '12 at 12:53
  • @Stephan sure it is, and I'd recommend that as the best way to do this. But this question was asked before `NSLayoutConstraint` was available. :) – Dave DeLong Jul 14 '12 at 22:12