cocoainterface-builderautolayoutnsscrollviewikimagebrowserview

Window becomes non-resizable after adding Autolayout constraints


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?


Solution

  • 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.