Window becomes non-resizable after adding Autolayout constraints - cocoa

I have an IKImageBrowserView inside a NSScrollView.
I added Autolayout constraints to fix the top of the scroll view to the textfield above it and the bottom of the scroll view to the bottom of the window.
The desired behaviour is, that the scroll view (and the IKImageBrowserView with it) will grow and shrink vertically when you grow and shrink the window vertically.
The actual behaviour is, as soon as i added the constraints, the window is no longer vertically resizable.
Why is that? How can I achieve the desired behaviour?

You can examine the constraints by doing:
NSArray* constraints = [window.contentView constraintsAffectingLayoutForOrientation:NSLayoutConstraintOrientationVertical];
NSLog(#"%#", constraints);
You could also do [window visualizeConstraints:constraints] to explore interactively.
See Auto Layout Guide: Resolving Auto Layout Issues – Debugging in Code.

Related

UIScrollView contentInset is set to nonZero when using autolayout

So I have the following view hierarchy :
A full size scrollView in my viewController's view with the following constraints :
These are the constraints on containerView (ignore the second last one, its a hacky semi-fix for my problem):
I have the status bar, the navigation bar and the tab bar visible.
The thing is that when I set a breakpoint to check the scrollView's contentInset, it shows 64 on top and 49 on bottom, left and right are zero.
There is no way to set contentInset in IB, I tried setting it in an IBAction to UIEdgeInsetZeio, but that didn't fix it either. This is screwing up my scrollview by adding space above and below my contentView, how can I fix this?
By default the view controller extends the view under the top navigation bar so your content will blur under a translucent navigation bar. This is controlled by edgesForExtendLayout which is managed in Storyboard via the Extend Edges setting.
By default, the scrollview will automatically adjust its content inset so the content appears below the top layout guide. This is controlled by automaticallyAdjustsScrollViewInsets which is also managed in Storyboard.
What you did was constrain the top of your scroll view to the top layout guide instead of the top of its superview. By doing this, you manually offset it by 64 points. However, the scrollview is still automatically insetting its content by 64 points, which is why you're seeing additional space above and below your scroll view.
Either constrain your scrollview to its superview (so its content scrolls under the top/bottom bars), or disable the view controller from automatically adjusting the scroll view inset.

UIScrollview scroll not working

UIScrollview scroll is not working when i tested application in device (iPhone 5), But scroll is working properly in iPhone 5/5s/6/6 Plus simulator. I am developing application using Xcode 6 and UIStoryboard with AutoLayout.
I set the top, bottom, left and right constraints of UIScrollview with relative to Superview. And i also set the constraints of every UIControl which is in the UIScrollview.
Has any one have solution regarding this issue?
Please see below screenshot for reference.
It's probably easiest to have the scroll view contain a single view, which then contains all of your scrollable content. That single view should be anchored to all 4 sides of the scroll view, and if it's only meant to scroll vertically (which is what your screenshot makes it look like), then set the content view to be the same width as the parent of the scroll view.
To make sure an UIScrollView scroll, you have to check
Size
Your content View is bigger than your Scroll View. If you want it to be scrolled vertically, make sure its higher; horizontally, wider.
Constraints
Make sure your Scroll View is pinned to its super view, Top, Bottom, Leading, Trailing.
Make sure your Content view of Scroll View DOES NOT have CenterY constraint set to Scroll View, cause that'd make content view stuck with Scroll View and it'd never be able to scroll. (That happens to me the last time I was stuck)
Interface Builder settings
Make sure the check in Interface Builder under Scroll View is checked:
Scrolling section, Scrolling Enabled.

NSCollectionView inside NSTableCellView doesn't resize

I want to show a NSCollectionView inside a NSTableCellView. I have it setup correctly, and it works for the most part, but the collectionView's scrollview doesn't seem to resize properly against the NSTableCellView, even though I have auto-layout constraints setup for this.
Is there anything I can do to setup constraints in a way that the scrollview resizes against the NSTableCellView (which should also let the collectionView also resize itself)?
EDIT:
To elaborate, what I really want to do is have the collectionView expand and resize as the window is resized, and have it take up the same width as the tableViewCell, and depending on the number of items in the collection view, resize the height of the outlineView & hence determine the height of the outlineView's row. It works fine when the collectionView is part of an ordinary view, but I can't get it to resize itself inside a NSTableCellView.
Firstly, remove all of the constraints you've set for your collectionview/scrollview.
Now, you will need to make 4 constraints, one for each of the leading, trailing, top and bottom space from the scrollview to its superview. Make sure width and height are not constrained. I've done this in a recent app I've made and it worked rather well.
EDIT: Below in the comments we figured out the column wasn't resizing so the constraints were correctly set.

NSView controls not resizing?

I have a NSView with a NSTableView inside of it.
If the view looks like this:
And the size & position properties for the Scollview (and tableview) look like this:
Then why when I resize the view, does it look like this:
Are my autosizing properties not set correctly? To my understanding they should be?
To make it clearer, you won’t see autoresizing behaviour whilst designing your view in Interface Builder unless the border of the subview coincides with the corresponding border of the superview and Live Autoresizing is enabled.
This behaviour exists because resizing the superview can be used to indicate that you want a certain margin between the subview area and the superview area — for instance, you might have a 100pt margin between the subview’s right border and the superview’s right border, and then increase that margin to, say, 200pt by dragging the superview handles.
Edit: On the other hand, if you want to resize the superview whilst keeping the margins according to the autoresizing mask, you can drag the superview handles whilst holding the alt/option key.
Use Cocoa Simulator (File -> Simulate Interface) in order to test your interface, including autoresizing behaviour.
The table with its scroll view will autoresize to your view's size only if you enter dimensions in by hand in Size info panel. They will not autoresize if you drag view's handles with mouse.

Why would NSWindow with NSTableView not resize?

Here is my IB setup:
http://img145.imageshack.us/img145/5929/picture1gxr.png
When both NSScrollView and NSTableView are set to autoresize and autofill (all the arrows in the Autosizing section are checked) my window does not resize. Actually it resizes, but by a pixel, as if it remembers that it is not supposed to resize after I start dragging the corner. If I uncheck the autofill arrows (disabling NSViewWidthSizable and NSViewHeightSizable) on the NSScrollView, the window resizes fine, but of course, the scroll view does not resize with it.
The weird thing is that in the situation where the window is "rigid" if I resize one of the NSTableView's columns beyond the view (thus causing a horizontal scroll bar to appear), I can resize the window but only until it reaches the size big enough to accommodate all the columns and then becomes rigid again.
Maybe you have set a fixed minimum/maximum size for the window?
Is this a feature or bug of BWSplitView? What if you make it an NSSplitView?
If it turns out to be a bug, you should report it.
Ah, I've reverted to my last good commit and rebuilt the view hierarchy and everything worked. It is probably a bug in BWSplitView, but I can't reproduce it anymore, so can't report really.

Resources