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

# NSTextViewportLayoutController

Manages the layout process inside the viewport interacting with its delegate.

```
class NSTextViewportLayoutController
```

## Overview

A viewport is a rectangular area within a flipped coordinate system expanding along the y-axis. With text contents, lines advance expanding the view in the current writing direction. The viewport defines the active area where the framework lays out text fragments. In most cases, the area corresponds to the user visible area with an additional over-scroll region.

## Topics

### Creating a viewport layout controller

[`-  initWithTextLayoutManager:`](/documentation/AppKit/NSTextViewportLayoutController/init(textLayoutManager:))

Creates a new instance with the text layout manager you provide.

### Accessing the layout manager

[`textLayoutManager`](/documentation/AppKit/NSTextViewportLayoutController/textLayoutManager)

Returns the text layout manager for this viewport layout controller.

### Responding to changes in viewport layout

[`delegate`](/documentation/AppKit/NSTextViewportLayoutController/delegate)

The delegate for the text layout manager object.

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

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

### Accessing the viewport characteristics

[`viewportBounds`](/documentation/AppKit/NSTextViewportLayoutController/viewportBounds)

Returns the visible bounds of the view, plus the overdraw area.

[`viewportRange`](/documentation/AppKit/NSTextViewportLayoutController/viewportRange)

Returns the text range of the current viewport layout.

[`-  adjustViewportByVerticalOffset:`](/documentation/AppKit/NSTextViewportLayoutController/adjustViewport(byVerticalOffset:))

Adjusts the viewport rect by the specified offset if needed.

[`-  layoutViewport`](/documentation/AppKit/NSTextViewportLayoutController/layoutViewport())

Performs layout in the viewport.

[`-  relocateViewportToTextLocation:`](/documentation/AppKit/NSTextViewportLayoutController/relocateViewport(to:))

Relocates the viewport to the location you specify.

## Relationships

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

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

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)