hockeyman
hockeyman

Reputation: 1183

center documentView in center of NSScrollView

How can I center my DocumentView (witch is subclass of NSOpenGLView) at NSScrollView?

Now it looks like this (gray area is NSScrollView bounds):

enter image description here

And I want it to look something like this:

enter image description here

Upvotes: 8

Views: 758

Answers (2)

Andrew
Andrew

Reputation: 7719

Subclass NSClipView and override -constrainBoundsRect: to return the centered rect. This is discussed at the the 45:30 mark in the fantastic presentation from WWDC 2013 - Session 215: Optimizing Drawing and Scrolling on OS X

Upvotes: 2

Axel K.
Axel K.

Reputation: 105

Use an intermediate NSView which has the document view centered in it (set its frame accordingly and probably set layout constraints the way it should behave). Put that view in the scroll view.

Upvotes: 0

Related Questions