scroll(_:by:)
Copies the visible portion of the view’s rendered image within a region and lays that portion down again at a specified offset .
Declaration
func scroll(_ rect: NSRect, by delta: NSSize)Parameters
- rect:
A rectangle defining a region of the view.
- delta:
A
NSSizestructure that specifies an offset fromaRect’s origin.
Discussion
This method is useful during scrolling or translation of the coordinate system to efficiently move as much of the view’s rendered image as possible without requiring it to be redrawn, following these steps:
Invoke scroll(_:by:) to copy the rendered image.
Move the view object’s origin or scroll it within its superview.
Calculate the newly exposed rectangles and either set the needsDisplay property to true or call setNeedsDisplay(_:) to draw them.
You should rarely need to use this method, however. The scroll(_:), scrollToVisible(_:), and autoscroll(with:) methods automatically perform optimized scrolling.