<!--
{
  "availability" : [
    "macOS: 10.0.0 - 10.14.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSView/scroll(_:by:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSView(im)scrollRect:by:"
  },
  "title" : "scroll(_:by:)"
}
-->

# 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 .

```
func scroll(_ rect: NSRect, by delta: NSSize)
```

## Parameters

`rect`

A rectangle defining a region of the view.

`delta`

A `NSSize` structure that specifies an offset from `aRect`’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:

1. Invoke [`scroll(_:by:)`](/documentation/AppKit/NSView/scroll(_:by:)) to copy the rendered image.
2. Move the view object’s origin or scroll it within its superview.
3. Calculate the newly exposed rectangles and either set the [`needsDisplay`](/documentation/AppKit/NSView/needsDisplay) property to <doc://com.apple.documentation/documentation/Swift/true> or call [`setNeedsDisplay(_:)`](/documentation/AppKit/NSView/setNeedsDisplay(_:)) to draw them.

You should rarely need to use this method, however. The [`scroll(_:)`](/documentation/AppKit/NSView/scroll(_:)), [`scrollToVisible(_:)`](/documentation/AppKit/NSView/scrollToVisible(_:)), and [`autoscroll(with:)`](/documentation/AppKit/NSView/autoscroll(with:)) methods automatically perform optimized scrolling.

## See Also

[`-  setBoundsOrigin:`](/documentation/AppKit/NSView/setBoundsOrigin(_:))

Sets the origin of the view’s bounds rectangle to a specified point.

[`-  translateOriginToPoint:`](/documentation/AppKit/NSView/translateOrigin(to:))

Translates the view’s coordinate system so that its origin moves to a new location.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)