0
votes

I'm trying to scroll an NSScrollView to the bottom of the view using this code:

NSPoint newScrollOrigin;
if ([[self.chatScreen documentView] isFlipped]) {
    newScrollOrigin=NSMakePoint(0.0,NSMaxY([[self.chatScreen documentView] frame])-NSHeight([[self.chatScreen contentView] bounds]));
} else {
    newScrollOrigin=NSMakePoint(0.0,0.0);
}
self.chatScreen.backgroundColor=[NSColor redColor];
[[self.chatScreen documentView] scrollPoint:newScrollOrigin];

which came from here: Apple doucmentation on scrolling

When I run my program, it partially scrolls to the bottom of the view, where the screen shows the top of the view (default starting position) but when I attempt to scroll, it jumps to the bottom of the page, where I can then scroll normally.

If I scroll around to any part of the view, the next time it receives an update (which triggers it to jump back to the bottom) it looks like nothing happened, until you try to scroll, which again causes it to jump back to the bottom of the page.

Thanks in advance.

1
It sounds like some scrolling code is triggered at unwanted times. If I understand right, it automatically scrolls when you try to scroll manually?Volker
Where do you call this code from?Flexicoder
@Flexicoder I'm calling the code from a separate threadAlex
@Volker It's scrolling when I want it to, except the screen isn't reflecting the new 'position' of the scrollviewAlex

1 Answers

0
votes

You need to scroll the clip view and not the document view.
The document view fills out the entire scroll view and the clip view is kind of an overlay which scrolls around deciding which parts are visible.

[[self.chatScreen contentView] scrollToPoint:newScrollOrigin];

Notice the scrollToPoint instead of NSView's layer backed scrollPoint After you scroll a NSClipView its always good practice to reflectScrolledClipView so that the scrollers update.

- (void)reflectScrolledClipView:(NSClipView *)aClipView;