I have an NSScrollView containing an NSImageView, which resizes based on various factors. When it resizes I have generally changed the image, so I scroll the NSScrollView to the top. This works fine. However, when I start to scroll the NSScrollView again, it moves a few pixels and then (most of the time) jumps to the bottom of the scroll. After it jumps once, it works as normal until I move the scroller to the top again. This is driving me insane. All I'm really doing is this:
[_imageView setImage: anNSImage];
NSRect frame;
NSSize imageSize = [anNSImage] size];
frame.size = imageSize;
frame.origin = NSZeroPoint;
[_imageView setFrame: frame];
[[_mainScrollview contentView] scrollToPoint: NSMakePoint(0, [_imageView frame].size.height - [_mainScrollview frame].size.height)];
Nick, thanks for your code. I modified your code and it works well now. First, you need to scroll the vertical scroller to top. Second, scroll the content view.
// Scroll the vertical scroller to top
if ([_scrollView hasVerticalScroller]) {
_scrollView.verticalScroller.floatValue = 0;
}
// Scroll the contentView to top
[_scrollView.contentView scrollToPoint:NSMakePoint(0, ((NSView*)_scrollView.documentView).frame.size.height - _scrollView.contentSize.height)];