开发者

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 la开发者_JAVA百科unch, 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.


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜