indragie
indragie

Reputation: 18132

NSScrollView incorrect content size

I have an NSScrollView that is the parent of a custom NSView subclass. The subclass uses the NSScrollView's contentSize method in order to layout its subviews.

The issue is that upon first launch, NSScrollView reports the contentSize wrong. It reports the size as being 15px more than it should be (the width of the scroller). So it seems to me that it is returning the contentSize without taking into account the scroller width; however, as soon as I adjust the frame of the scroll view (by resizing, etc.) the content size is reported properly. It seems to be just a problem upon initial launch.

Should this be reported as a bug, and are there any good solutions to this? I could use the dirty way of performing a check during layout to see if its the first time the method has been called, and then deduct 15px from the content size, but if there's something better, that would be appreciated.

Upvotes: 2

Views: 1639

Answers (3)

user2970742
user2970742

Reputation:

Are you using the option to hide/show automatically the scrollbars?

Upvotes: 0

Carlos Barbosa
Carlos Barbosa

Reputation: 3083

I just came across a similar problem and the way I solved it was to observe the notification NSViewFrameDidChangeNotification on the Scroll view's content view (in your case the custom NSView).

This notification gets triggered when a scrollbar is added/removed from the scroll view, at which point you can reposition your view's content.

Upvotes: 2

NSResponder
NSResponder

Reputation: 16861

When are you checking the content size? Is it happening as your view is being instantiated from the nib file, or after the nib has been fully unarchived?

What I would probably do is invoke your layout method from -viewDidMoveToWindow: or -awakeFromNib

Upvotes: 0

Related Questions