Re: ambiguous layout for documentView in NSScrollView
Re: ambiguous layout for documentView in NSScrollView
- Subject: Re: ambiguous layout for documentView in NSScrollView
- From: Kyle Sluder <email@hidden>
- Date: Sun, 17 Mar 2013 09:37:20 -0700
>>>> To pin the height of the documentView to its NSScrollView, I use the
>>>> following constraint:
>>>> NSDictionary * scrollViewsDict =
>>>> NSDictionaryOfVariableBindings(documentView);
>>>>
>>>> [scrollView addConstraints: [NSLayoutConstraint
>>>> constraintsWithVisualFormat:
>>>> @"V:|[documentView]|" options: 0 metrics: nil views:
>>>> scrollViewsDict]];
>>>
>>> You have not shown any other vertical constraints for your subviews. If
>>> all you have are the ">= 70" constraints, there are infinitely many
>>> solutions to your document view height. That would be the source of your
>>> ambiguity.
>>
>> I neglected to mentioned that in my documentView's updateConstraints
>> method that I add @"V:|[subview(>=70)]|" to self for each subview.
Actually, you didn't fail to mention them. I misinterpreted your scroll view constraint. (This is why I *much* prefer using diagrams when discussing constraints.)
So that we're all on the same page: your internal vertical constraints can be expressed as @"V:|[subview1(>=70)][subview2(>=70)]…|". Then you add a constraint of @"|[documentView]|" to your scroll view.
This is wrong right off the bat, because the scroll view is not the superview of the documentView; the clip view is.
It's unclear to me whether the "|" character in your code results in constraining the documentView to the clip view or the scroll view. If it's the latter, the clip view has a bounds.origin translation, so you're not supposed to set up any constraints that cross it in the view hierarchy.
But even if you had added it to the clip view, it is still not correct. The clip view's height is governed by an autoresizing mask constraint. As soon as your scroll view gets shorter than 70 points tall (plus the height of the legacy horizontal scroller, if it is visible) you will have a constraint violation exception.
--Kyle Sluder
_______________________________________________
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