How can I center my DocumentView (the witch is a subclass of NSOpenGLView) in an NSScrollView ?
DocumentView
NSScrollView
Now it looks like this (the gray area is the borders of the NSScrollView):
And I want it to look something like this:
Use an intermediate NSView, in which there is a document view centered on it (set its frame accordingly and, possibly, set layout constraints as it should behave). Place this view in a scroll view.
Subclass NSClipView and override -constrainBoundsRect: to return a centered rectangle. This is discussed at around 45:30 in the fantastic presentation of WWDC 2013 - Session 215: Optimizing drawing and scrolling on OS X
NSClipView
-constrainBoundsRect: