Hi, Ok, when I initially asked for some help or if there were any additional documentation I was pointed to this:
http://natashatherobot.com/ios-autolayout-scrollview/ Which applies to iOS *only*. I was then told: Yes, there's a pretty huge difference: UIScrollView doesn't have a contentView. Here's a pretty simple and straightforward blog post about doing this on the Mac: http://blog.bjhomer.com/2014/08/nsscrollview-and-autolayout.html From this site: So, you've got an NSScrollView, and you want to add some content that is sized via auto layout constraints. Perhaps you found the "Auto Layout by Example" documentation in the Mac developer library, and discovered that though it contains a section titled Using Scroll Views with Auto Layout, the example is actually for UIScrollView, not NSScrollView. Given the significant differences between the two, that simply won't work. So, given that I have this in a NIB file: Window Initially - Width=846, Height=594 View (Matches Window) NSScrollView Initially - X=20,Y=20, Width=806, Height=554 FlippedClipView View As you can see, the layout of the subviews inside NSScrollView is quite different from UIScrollView, so given the above, what do in terms on setting constraints on the above views? Should “FlippedClipView” be constrained by NSScrollView? Also does the view inside “FlippedClipView” need constraints added? The code at blog.bjhomer.com does this: _scrollView = [[NSScrollView alloc] initWithFrame:self.bounds]; _scrollView.translatesAutoresizingMaskIntoConstraints = YES; _scrollView.autoresizingMask = NSViewHeightSizable | NSViewWidthSizable; _scrollView.hasVerticalScroller = YES; _scrollView.identifier = @"ScrollView"; [self addSubview:_scrollView]; But this cannot (AFAIK) be reproduced in XCode/IB with a pre-created Scroll View. Do I have to figure out what constraints are generated for the Scroll View when the above setting are applied and then manually place then on the Scroll View in IB? Also when you add an NSScrollView in XCode/IB it auto-magically adds a Clip View (I change the Class in IB to FlippedClipView) and it’s sibling View. So I guess I have to set the constraints for this myself. In the code from the above link, it does this: _scrollContentContainer = [[FlippedView alloc] initWithFrame:_scrollView.contentView.bounds]; _scrollContentContainer.translatesAutoresizingMaskIntoConstraints = NO; _scrollContentContainer.identifier = @"Content container”; NSDictionary *views = NSDictionaryOfVariableBindings(_scrollContentContainer); NSArray *hConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_scrollContentContainer]|" options:0 metrics:nil views:views]; NSArray *vConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_scrollContentContainer]" options:0 metrics:nil views:views]; [_scrollView.contentView addConstraints:hConstraints]; I’m trying to figure out if its possible to set this up in XCode/IB (and if so, how), or if I’d be better off doing it all in code. Cheers Dave > On 4 Sep 2015, at 20:39, Luther Baker <lutherba...@gmail.com> wrote: > > I may not be following the entire thread very well - but as you likely know, > with auto-layout, the scrollview's content size is literally determined by > its contents. It is generally simple to bind the scrollview edges to the > parent you mention but I think your next step is to properly size the Stack > View ... (child view) so that the ScrollView knows how big to make it's > content view. > > On iOS, I can set width and height constraints between the child view and its > parent ScrollView's frame ... telling the child view to be the same width and > height as the ScrollView's frame. Note that these constraints are not > associated with the ScrollView's content view. Indeed, they drive the content > view's size. Think of it as the content view "reaching back" and finding out > how big it should be by constraining to sizes up the hierarchy. > > I assume that model ports over to MacOS ... but I could be wrong. > > Also, I'm guessing this bulletin was presented earlier but if not > https://developer.apple.com/library/ios/technotes/tn2154/_index.html > > HTH, > -Luther _______________________________________________ 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