Is there a simple way to get an NSScrollView
to adapt to its document view changing size when using auto layout?
I have tried to call both setNeedsUpd
The problem of course is that when adding the document view, Cocoa will automatically create some hard constraints in the view that the document view is inserted into, i.e., the clip view.
So the answer to my own question is simple, just use:
// Assume self.docView is an IBOutlet populated with
// an NSView subclass
self.docView.translatesAutoresizingMaskIntoConstraints = NO;
before you add the document view to the scroll view:
self.scrollView.documentView = self.docView;
Now, since there are no auto-generated constraints on the layout of the document view in the clip view, you will need to add them explicitly. Otherwise, the doc view's contents will just be rendered at their intrinsic size in the upper left corner of the scroll view.