Center documentView in the center of NSScrollView

How can I center my DocumentView (the witch is a subclass of NSOpenGLView) in an NSScrollView ?

Now it looks like this (the gray area is the borders of the NSScrollView):

enter image description here

And I want it to look something like this:

enter image description here

+7
source share
2 answers

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.

0
source

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

0
source

All Articles