Re: NSScrollView autolayout (10.10)
Re: NSScrollView autolayout (10.10)
- Subject: Re: NSScrollView autolayout (10.10)
- From: Roland King <email@hidden>
- Date: Thu, 08 Jan 2015 18:01:50 +0800
> On 8 Jan 2015, at 00:57, Ken Thomases <email@hidden> wrote:
>
>> More generally, is this how you’re supposed to set up a view which has intrinsic content size inside a scroll view in IB, pin that view to the NSView IB gives you, then pin that to the clipview on 3 sides only and flip the clip (why?).
>>
>> I did try changing the class of the NSView I can’t delete to NSStackView and avoid the middle man, very bad things happened, constraints were generated in constraint language which didn’t parse, so I decided to put it back where it was.
>
> For what it's worth, I dragged an NSStackView into a window. Then, I chose Editor > Embed In > Scroll View. That resulted in:
>
> +- NSScrollview
> +- NSClipView
> +- NSStackView
>
> Then I selected Reset to Suggested Constraints for the whole window. That added leading, trailing, top, and bottom constraints for the scroll view to its superview and the same for the stack view to the clip view. The fact that the stack view was constrained on all sides meant that it would never scroll. Rather, the scroll view would grow to fit it and the window would grow to fit that. I then deleted the bottom constraint between the stack view and the clip view, similar to what you have. That resulted in what you described: the stack view was positioned at the bottom of the clip view when it was shorter than the scroll view's content height.
Embed in ScrollView was something I’d forgotten about, using that does make more sense and I’ve made another version which goes that way, that removes one view.
>
> I didn't try subclassing NSClipView to make it flipped. (I had thought that clip views were flipped by default, but that may not apply with auto layout.) I assume it would fix the placement of the stack view as you described.
>
> There's another way to fix that, though. Rather than removing the bottom constraint between the stack view and the clip view, change it to an inequality. Make it so that the stack view is _at least_ as tall as the clip view (stack view bottom is greater than or equal to the clip view bottom). When the scroll view is taller than needed to show the stack view's intrinsic height, the stack view is made taller to fill the content size and thus subviews in its top section will appear at the top of the scroll view. When the scroll view is shorter than needed (either because the stack view grows or because the window is made smaller), the stack view is not forced to be shorter. Rather, it is allowed to scroll vertically, since the document (stack) view is taller than the content (clip) view.
I finally did make this work when I got the constraint the right way around. I see what’s going on there. I eventually today found the WWDC video from 2013 which mentions ever so briefly how to put a stack view in a scroll view and that mentions the clip view must be flipped (and they leave out the bottom constraint as I did), but either works just fine and your way doesn’t require the subclass which is cool.
Thanks for the help. Now .. animation time ..
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden