ambiguous layout for documentView in NSScrollView
ambiguous layout for documentView in NSScrollView
- Subject: ambiguous layout for documentView in NSScrollView
- From: Chuck Soper <email@hidden>
- Date: Sat, 16 Mar 2013 17:38:25 -0700
- Thread-topic: ambiguous layout for documentView in NSScrollView
Thanks to Kyle Sluder's recent "Re: guidelines for using autolayout with
NSScrollView?" post, I have a better understanding of what's involved in
getting auto layout to work with NSScrollView.
I thought I'd create a new thread because I'm not sure I need to take that
general approach for my specific case. My user interface works fine. The
problem is that my documentView is ambiguous, but I think I can ignore
that fact for my particular case. Here are the details:
My documentView is a custom NSView subclass.
From awakeFromNib in my documentView, I call:
[self setTranslatesAutoresizingMaskIntoConstraints:NO];
I override updateConstraints in my documentView, and set up the following
constraints (built in a for loop for 1 to N subviews):
@"H:|[subview1][subview2][subview3]|"
Each subview has an "NSLayoutConstraint * widthConstraint;" ivar that
holds the absolute width. Visually, it looks like this:
@"H:[subview(==120)]"
I also added some minimum width and height constraints that look like this:
@"H:[subview(>=80)]" and @"V:[subview(>=70)]"
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]];
Actions and behavior:
- Resizing the window changes the height of the documentView but not the
width.
- The width of each subview can be changed by adjusting the constraint
constant, like this: subview1.widthConstraint.constant = 220.0;
- Subviews can be added or removed to/from documentView.subviews then
calling [documentView setNeedsUpdateConstraints:YES];
All of this works great. The documentView resizes and scrolls as expected.
The problem is that [documentView hasAmbiguousLayout] returns YES. When I
visualize the documentView's constraints and press the Exercise Ambiguity
button, nothing changes. This is because all the subviews have an absolute
width.
The question is: can I safely ignore the fact that my documentView is
ambiguous for my particular case and hope that the problem will go away
with 10.9?
Chuck
_______________________________________________
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