Re: NSStackView layout issues
On 23 Nov 2014, at 16:48, SevenBits sevenbitst...@gmail.com 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 (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
NSStackView layout issues
Begin forwarded message: Subject: Re: NSStackView layout issues From: SevenBits sevenbitst...@gmail.com Date: November 24, 2014 at 7:53:15 PM EST To: Jonathan Mitchell jonat...@mugginsoft.com Hello Jonathan, That seems to have done the trick, thank you. That you for directing me to TSStackView, I will take a look at it. — SevenBits On Nov 24, 2014, at 5:17 AM, Jonathan Mitchell jonat...@mugginsoft.com wrote: On 23 Nov 2014, at 16:48, SevenBits sevenbitst...@gmail.com 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 (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/sevenbitstech%40gmail.com This email sent to sevenbitst...@gmail.com signature.asc Description: Message signed with OpenPGP using GPGMail ___ 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
NSStackView layout issues
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. My problem is that I have two identical NSScrollView objects (each with an embedded NSTextView) which are loaded from nib files. When I add these views to my stack view, the one that is added first takes up 100% of the available space, and the second collapses completely down to the bottom with a height of 2 pixels while taking up all available horizontal space. In effect, this looks like the first view is the only one in the window. Here's what it currently looks like: http://i.stack.imgur.com/2tEwm.png It's nearly impossible to see in this example because of the background color, but the scroll view ends a couple pixels above the bottom of the window. Here's a better view from the view hierarchy inspector, where I have this 2 pixel high view selected: http://i.stack.imgur.com/XJeG5.png Here's the relevant setup code: // Load the stack view self.inputViewController = [[NSViewController alloc] initWithNibName:@Document_TextInputView bundle:nil]; self.textView = (NSTextView *)[[(NSScrollView *)self.inputViewController.view contentView] documentView]; self.outputViewController = [[NSViewController alloc] initWithNibName:@Document_TextOutputView bundle:nil]; self.outputView = (NSTextView *)[[(NSScrollView *)self.outputViewController.view contentView] documentView]; // Add all views into the stack view [self.stackView addView:self.inputViewController.view inGravity:NSStackViewGravityTop]; [self.stackView addView:self.outputViewController.view inGravity:NSStackViewGravityBottom]; self.stackView.orientation = NSUserInterfaceLayoutOrientationVertical; // Load the text into the window. [self.textView setString:self.cachedText]; [self.outputView setString:@=== PROGRAM OUTPUT ===\n]; [self.codeActionSegmentedControl setEnabled:NO forSegment:1]; 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. Thanks a lot, — SevenBits signature.asc Description: Message signed with OpenPGP using GPGMail ___ 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