• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSStackView layout issues
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSStackView layout issues


  • Subject: Re: NSStackView layout issues
  • From: Jonathan Mitchell <email@hidden>
  • Date: Mon, 24 Nov 2014 10:17:19 +0000


> On 23 Nov 2014, at 16:48, SevenBits <email@hidden> wrote:
>
> Hello Cocoaphiles, ;)
>
> I've just started experimenting with NSStackView, and I'm having a very interesting problem which I can't solve. I've scoured the auto layout guides on Apple's website as well as the NSStackViewdocumentation, and can't seem to find anything.
>
> From what I understand, the intrinsic content size should prohibit the view from getting shrunk this small. I'm not too familiar with NSStackView, so any help would be appreciated.
>
I think you will find that NSScrollView -intrinsicContentSize will return {NSViewNoIntrinsicMetric, NSViewNoIntrinsicMetric}.
i.e: a scroll view doesn’t report an intrinsic content size.

NSStackView calls -fittingSize to determine the size for its subviews.
If you add a subview to a vertical NSStackView without a fully constrained height it collapses to zero - ish.
Often, if you ask XCode to add contains to your view it will not fully constrain the height of the view.
This cases them to misbehave in an NSStackView.

So the point is add some constraints!
NSStackView is supremely useful once you get your head around the constraint basics.

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

    NSLog(@"- intrinsicContentSize : %@", NSStringFromSize(self.textScrollView1.intrinsicContentSize));
    NSLog(@"- fitting size: %@", NSStringFromSize(self.textScrollView1.fittingSize));

    self.textScrollView1.translatesAutoresizingMaskIntoConstraints = NO;
    self.textScrollView2.translatesAutoresizingMaskIntoConstraints = NO;

    self.stackView.alignment = NSLayoutAttributeWidth;

    [self.stackView addView:self.textScrollView1 inGravity:NSStackViewGravityTop];
    [self.stackView addView:self.textScrollView2 inGravity:NSStackViewGravityTop];

    NSDictionary *views = NSDictionaryOfVariableBindings(_textScrollView1, _textScrollView2);
    [self.stackView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_textScrollView1(==_textScrollView2)]"
                                                                             options:0
                                                                             metrics:nil
                                                                               views:views]];
}

I use the following with view -hidden bindings to manipulate complex view stacks

https://github.com/mugginsoft/TSStackView

Jonathan
_______________________________________________

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


  • Prev by Date: Weird crash in FSRefCreate while saving NSDocument
  • Next by Date: Re: codesign v2 problem on 10.8.5 and earlier
  • Previous by thread: Re: Weird crash in FSRefCreate while saving NSDocument
  • Next by thread: Altering the size of UISlider's “slider ball”
  • Index(es):
    • Date
    • Thread