Getting NSWindow resizing right in an auto layout world
<p>I'm having problem getting vertical window resizing working with an auto layout scroll view.</p>

<p><strong>What I Want</strong></p>

<p>I would like to replicate, as closely as possible, my app's current window resizing behaviour. The width of the window is flexible, but the height of the window should generally track the height of the contents. Specifically:</p>

<ol>
<li>Normally, the window automatically resizes its height to exactly<br>
match its contents (with the exception of #2).</li>
<li>The user can choose to manually resize the window so it's smaller than its
contents, in which case the imbedded scroll view will scroll the
contents. Once made shorter, the window remains that height until manually
resized or the contents becomes equal or smaller than the window again.</li>
<li>If the contents grows to the point that the bottom of the window
bumps into the dock or screen bounds, the window's height is pinned
to that height, just as if the user has resized it.</li>
</ol>

<p><strong>What I've Got</strong></p>

<p>I created a window with a set of representative subviews that mimic the basic needs of my app. The window's hierarchy is simple:</p>

<pre><code>Window
    NSView (contentView)
        NSScrollView
            NSClipView (NSScrollView.contentView)
                NSView (NSScrollView.documentView)
                    A bunch of standard and custom subviews with constraints
</code></pre>

<p>You can download the test project here (macOS 10.12/Xcode 8): <a href="http://mbx.cm/t/4FUGY" rel="nofollow">http://mbx.cm/t/4FUGY</a></p>

<p>I've organized the various subviews so they have a flexible width, but the constraints define exactly one possible height. The parent scroll view fills the content view of the window.</p>

<p>The auto layout stuff works great. The window automatically resizes to match the size of the contents. If the height of the contents changes, the height of the window changes to match. Awesome.</p>

<p><strong>What I Can't Get to Work</strong></p>

<p>I have had no luck getting NSWindow to let me manually resize its height. The resize indicator (when hovering over the edge) shows that I can alter the window's width, but not its height.</p>

<p>I initially thought "Oh, that's got to be a compression resistance priority in one of the scroll views." But I can find no combination of compression resistance or hugging priorities that will alter this behavior. I've tried setting the priorities of the scroll view itself, and on the documentView (which makes no sense to me, but I tried anyway). I tried the values 749, 499, 49, and 1 in every combination I could think of.</p>

<p>I've searched for every problem that seemed released to this, but most of the posted questions seemed to be addressing different problems.</p>

<p>I added a "Dump" button to log the vertical constraints. Everything listed appears to be as expected, except for a handful of NSAutoresizingMaskLayoutConstraint objects that I don't understand. However, these appear to be constraints between the document view and the clip view, so I assume those are automatically created and aren't part of the problem.</p>

<pre><code>&lt;NSLayoutConstraint:0x608000082580 PartBoxView:0x608000140840'Part B'.height == 96   (active)&gt;
&lt;NSLayoutConstraint:0x608000083de0 V:[PartBoxView:0x608000140840'Part B']-(0)-|   (active, names: '|':NSView:0x6080001212c0 )&gt;
&lt;NSLayoutConstraint:0x608000083e80 V:[PartBoxView:0x608000140370'Part A']-(NSSpace(8))-[PartBoxView:0x608000140840'Part B']   (active)&gt;
&lt;NSLayoutConstraint:0x608000082da0 V:|-(0)-[NSScrollView:0x6080001c10e0]   (active, names: '|':NSView:0x608000121400 )&gt;
&lt;NSLayoutConstraint:0x608000083430 V:|-(0)-[NSView:0x6080001212c0]   (active, names: '|':NSClipView:0x10040e2a0 )&gt;
&lt;NSLayoutConstraint:0x608000081e00 V:[NSScrollView:0x6080001c10e0]-(0)-|   (active, names: '|':NSView:0x608000121400 )&gt;
&lt;NSAutoresizingMaskLayoutConstraint:0x650000082b20 h=-&amp;- v=-&amp;- NSView:0x608000121400.minY == 0   (active, names: '|':NSThemeFrame:0x102504ea0'Window' )&gt;
&lt;NSAutoresizingMaskLayoutConstraint:0x6500000823f0 h=-&amp;- v=-&amp;- NSClipView:0x10040e2a0.minY == 1   (active, names: '|':NSScrollView:0x6080001c10e0 )&gt;
&lt;NSLayoutConstraint:0x608000083480 V:[NSView:0x6080001212c0]-(0)-|   (active, names: '|':NSClipView:0x10040e2a0 )&gt;
&lt;NSAutoresizingMaskLayoutConstraint:0x650000082440 h=-&amp;- v=-&amp;- V:[NSClipView:0x10040e2a0]-(1)-|   (active, names: '|':NSScrollView:0x6080001c10e0 )&gt;
&lt;NSLayoutConstraint:0x608000083d40 V:|-(0)-[PartBoxView:0x608000140370'Part A']   (active, names: '|':NSView:0x6080001212c0 )&gt;
&lt;NSLayoutConstraint:0x608000083c50 V:[NSImageView:0x608000161bc0]-(20)-|   (active, names: '|':PartBoxView:0x608000140370'Part A' )&gt;
&lt;NSLayoutConstraint:0x608000083bb0 V:|-(20)-[NSImageView:0x608000161bc0]   (active, names: '|':PartBoxView:0x608000140370'Part A' )&gt;
&lt;NSLayoutConstraint:0x608000083660 NSImageView:0x608000161bc0.height == 64   (active)&gt;
</code></pre>

<p>I'm hoping someone with auto layout experience can tell me how to get #2 working. I'm pretty sure #3 will require some custom code, but #2 is the big hurdle.</p>

<p><strong>The Background</strong></p>

<p>I'm in the process of giving my app a major facelift. It's a pretty big app, so I started by creating a set of test projects to test out some of the new UI and techniques.</p>

<p>The first big undertaking is converting everything to auto layout. Most of it looks like it will be fairly smooth, and I'm looking forward to some of the many benefits of auto layout.</p>