Automatically grow document view of NSScrollView using auto layout?
Posted
by
Monolo
on Stack Overflow
See other posts from Stack Overflow
or by Monolo
Published on 2012-05-29T20:03:57Z
Indexed on
2012/10/29
11:01 UTC
Read the original article
Hit count: 330
Is there a simple way to get an NSScrollView
to adapt to its document view changing size when using autolayout (the Lion feature)?
I have tried to call both setNeedsUpdateConstraints:
and setNeedsLayout:
on the document view, the clip view and the scroll view, without any results.
fittingSize
of the document view reports the correct size.
An NSPopover
in conjunction with an NSViewController
handles this nicely, with the popover growing and shrinking as needed, and I was hoping to get a similar simple and robust behaviour with the scroll view. I have checked the documentation for scroll views, but they don't seem to be updated to use autolayout
.
Edited to clarify:
The problem I experience is that the document view, which holds subviews, is not re-sized when the subviews change their size, even if they call invalidateIntrinsicContentSize
. The contents of the document view are hence clipped to the original size of the document view as they grow. The document view is created in a nib and set as the scroll view's document view in an awakeFromBib
method.
What I hoped to obtain was that the document view frame would automatically be adjusted to when its fittingSize
changes, and the scrollbars updated accordingly.
NSPopover
does something similar - provided that the subviews of the content controller's view have the constraints set right and various content hugging values are high enough (higher than the hidden popover window's hight constraint priority, for one).
© Stack Overflow or respective owner