I can’t figure out how to actually use NSScrollview. I dragged the scroll view object onto an NSWindow in the interface builder. I then dragged some NSButtons onto the scroll view. My question is:
How do I actually make it scroll down, for example, 2x the original height?
Of course the user can scroll automatically using their UI. I assume what you want to do is to scroll programmatically.
A bit of background: An
NSScrollViewhas adocumentView, which is the underlying view that the scroll view shows a part of, and aclipView, which is the view that is shown on the screen. So the clip view is like a window into the document view. To scroll programmatically you tell the document view to scroll itself in the clip view.You have two options on how to scroll programmatically:
- (void)scrollPoint:(NSPoint)aPoint–– This scrolls the document so the given point is at the origin of the clip view that encloses it.- (BOOL)scrollRectToVisible:(NSRect)aRect–– This scrolls the document the minimum distance so the entire rectangle is visible. Note: This may not need to scroll at all in which case it returns NO.So, for example, here is an example from Apple’s Scroll View Programming Guide on how to scroll to the bottom of the document view. Assuming you have an
IBOutletcalledscrollViewconnected up to theNSScrollViewin your nib file you can do the following: