swiftxcodensviewnsscrollview

Content of NSScrollView sticks at bottom when resizing


When I add a custom NSView to my NSScrollView via documentView and resize the window the content sticks always to the bottom of the window (so the scroll view is always scrollt to the bottom when the window is resized).
Is there a way to keep the scroll view scrolled to the top when the window is resized?

Original

Resized

Edit: Uploaded reproducible example: https://github.com/nathasmike/sample1


Solution

  • The autoresizing mask of the custom view is translated into constraints. To prevent this do

    myCustomView.translatesAutoresizingMaskIntoConstraints = false
    myScrollView.documentView = myCustomView
    

    Add constraints to the custom view and its subviews.

    Another solution is removing the autoresizing mask from the custom view in the xib.