Search code examples
objective-cmacosxibnsscrollviewnsclipview

NSScrollView Confusion


Forgive me for this being a fairly vague question on NSScrollView classes. I am just not really understanding them, despite having read up on them a bunch.

I have a NSViewController subclass which has a xib. In this view I drop in an NSScrollView. I connect an IBOutlet from the view controller class.

This is where I get confused.

What is the difference between the NSScrollView documentView and clipView? When added inside the xib the scrollview is given an NSClipView. Why?

If I want to add a subview to my scrollview inside the xib, I can only drop a view into the NSClipView of the NSScrollView and not the scrollview directly. I also see, when I resize the NSClipView so that itself, clips a subview I dropped in, scroll bars appear on the scrollview. However, when I run my app, I can't scroll. Secondly, the subviews don't appear when the app is running anyway.

Would someone explain how an NSScrollView works? Everything I have read on it thus far hasn't made it click with me.


Solution

  • The clip view and scroll view work together to provide the scrolling behaviour. The clip view does the actual clipping of the document view (which is the view you want to present in the scroll view).

    The scroll/clip view largely know how to behave by querying the size of the document view, so it's important that you have configured your NSView-subclass to behave correctly in this way by (typically) calling [self setFrameSize:newSize] whenever the content changes. If you get this right then it should just work

    In order to solve the actual issues you are facing, however, I would need to see some code, so if you can reproduce the problem within a simple self-contained Xcode project that I can look at, then that is the best way forward (however note I won't be able to look at it at the current time).