Thanks Ken. I suspected it was something like that but didn't know what to
do about it. It also hadn't occurred to me that making the text field
centered didn't necessarily imply anything about the size of the containing
view. With no constraints on the sizes of contained view, it seems that
NSStackView scaled one view down to zero size while scaling the other one
up to fill the itself. Neither choice violates any constraints, though it
wasn't what I expected.

Adding a fixed height constraint to the subviews makes both visible.
Likewise, adding other height constraints like setting the equivalent of
@"V:|-[subview2]-" makes both visible (with different sizes). Looking at
the demo project, I see now that there are constraints with similar effect,
which is why it works.



On Mon, Nov 11, 2013 at 6:29 PM, Ken Ferry <kenfe...@gmail.com> wrote:

>
> Hi Tom,
>
> I think the problem here is that if you have view A containing textField,
> and textField is centered in A, there's no constraint expressing anything
> about A's height. A can go to zero height and still have the textField
> centered within it.
>
> If you added something giving a height (or fastened the edges of A to the
> textField), that'd probably do it.
>
> -ken
>
> On Fri, Nov 8, 2013 at 5:02 PM, Tom Harrington <atomicb...@gmail.com>wrote:
>
>> I'm trying to use NSStackView in what should be the most basic way
>> possible. I create the stack view and add two subviews. But only one of
>> them is ever visible.
>>
>> I'm creating the stack view in code (in my app delegate, for purposes of a
>> test project):
>>
>>     NSStackView *stackView = [NSStackView stackViewWithViews:@
>> [self.subview1,
>> self.subview2]];
>>
>>     stackView.orientation = NSUserInterfaceLayoutOrientationVertical;
>>
>>     stackView.alignment = NSLayoutAttributeCenterX;
>>
>>     stackView.spacing = 0;
>>
>>     [self.window.contentView addSubview:stackView];
>>
>>     [self.window.contentView addConstraints:[NSLayoutConstraint
>> constraintsWithVisualFormat:@"H:|-(50)-[stackView]-(50)-|"
>>
>>
>>         options:0
>>
>>
>>         metrics:nil
>>
>>
>>           views:NSDictionaryOfVariableBindings(stackView)]];
>>
>>     [self.window.contentView addConstraints:[NSLayoutConstraint
>> constraintsWithVisualFormat:@"V:|-(50)-[stackView]-(50)-|"
>>
>>
>>         options:0
>>
>>
>>         metrics:nil
>>
>>
>>           views:NSDictionaryOfVariableBindings(stackView)]];
>>
>> The two subviews subview1 and subview2 are just plain NSViews, each with
>> an
>> NSTextField label subview constrained to be in the center.
>>
>> At run time, only one subview is visible-- the last one in the array. It's
>> resized to fill the entire stack view. If I resize the window, the stack
>> view and the one visible subview also resize, but no window size ever gets
>> both subviews showing.
>>
>> Obviously I'm missing something basic about stack views, but I don't know
>> what. I've been looking at Apple's InfoBarStackView demo app but haven't
>> worked out which detail it has that I don't (Apple's demo:
>>
>> https://developer.apple.com/library/mac/samplecode/InfoBarStackView/Introduction/Intro.html
>> )
>>
>> --
>> Tom Harrington
>> atomicb...@gmail.com
>> AIM: atomicbird1
>> _______________________________________________
>>
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>
>> 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:
>> https://lists.apple.com/mailman/options/cocoa-dev/kenferry%40gmail.com
>>
>> This email sent to kenfe...@gmail.com
>
>
>


-- 
Tom Harrington
atomicb...@gmail.com
AIM: atomicbird1
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to