<!--
{
  "availability" : [
    "macOS: 12.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextViewportLayoutControllerDelegate",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextViewportLayoutControllerDelegate"
  },
  "title" : "NSTextViewportLayoutControllerDelegate"
}
-->

# NSTextViewportLayoutControllerDelegate

Optional methods that delegates implement to respond to viewport layout changes.

```
protocol NSTextViewportLayoutControllerDelegate : NSObjectProtocol
```

## Topics

### Responding to changes in the viewport

[`func textViewportLayoutController(NSTextViewportLayoutController, configureRenderingSurfaceFor: NSTextLayoutFragment)`](/documentation/AppKit/NSTextViewportLayoutControllerDelegate/textViewportLayoutController(_:configureRenderingSurfaceFor:))

The method the framework calls when the layout controller lays out a text layout fragment in the UI.

[`func textViewportLayoutControllerDidLayout(NSTextViewportLayoutController)`](/documentation/AppKit/NSTextViewportLayoutControllerDelegate/textViewportLayoutControllerDidLayout(_:))

The method the framework calls when the text viewport layout controller finishes its layout process.

[`func textViewportLayoutControllerWillLayout(NSTextViewportLayoutController)`](/documentation/AppKit/NSTextViewportLayoutControllerDelegate/textViewportLayoutControllerWillLayout(_:))

The method the framework calls before the text viewport layout controller starts its layout process.

[`func viewportBounds(for: NSTextViewportLayoutController) -> CGRect`](/documentation/AppKit/NSTextViewportLayoutControllerDelegate/viewportBounds(for:))

Returns the current viewport, which is the view visible bounds plus the overdraw area.

### Instance Methods

[`func textViewportLayoutController(NSTextViewportLayoutController, cacheRenderingSurface: any NSTextViewportRenderingSurface, for: any NSTextViewportRenderingSurfaceKey)`](/documentation/AppKit/NSTextViewportLayoutControllerDelegate/textViewportLayoutController(_:cacheRenderingSurface:for:))

Asks the delegate to cache a rendering surface for later retrieval.

[`func textViewportLayoutController(NSTextViewportLayoutController, retrieveCachedRenderingSurfaceFor: any NSTextViewportRenderingSurfaceKey) -> any NSTextViewportRenderingSurface`](/documentation/AppKit/NSTextViewportLayoutControllerDelegate/textViewportLayoutController(_:retrieveCachedRenderingSurfaceFor:))

Asks the delegate to return a previously cached rendering surface.

[`func textViewportLayoutControllerReceivedSetNeedsLayout(NSTextViewportLayoutController)`](/documentation/AppKit/NSTextViewportLayoutControllerDelegate/textViewportLayoutControllerReceivedSetNeedsLayout(_:))

Triggers relayout of the view.

## Relationships

### Conforming Types

[`NSTextView`](/documentation/AppKit/NSTextView)

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

---

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)