<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/onScrollVisibilityChange(threshold:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE24onScrollVisibilityChange9threshold_QrSd_ySbctF"
  },
  "title" : "onScrollVisibilityChange(threshold:_:)"
}
-->

# onScrollVisibilityChange(threshold:_:)

Adds an action to be called when the view crosses the threshold to be considered on/off screen.

```
nonisolated func onScrollVisibilityChange(threshold: Double = 0.5, _ action: @escaping (Bool) -> Void) -> some View
```

## Parameters

`threshold`

The amount required to be visible within the viewport of the parent
view before the `action` is fired. By default when the view has crossed more than 50%
on-screen, the action will be called.

`action`

The action which will be called when the threshold has been reached.

## Discussion

Use this modifier to be informed when the view has crossed the
provided threshold to be considered on/off screen.

```
struct VideoPlayer: View {
    @State var playing: Bool

    var body: some View {
        Group {
            // ...
        }
        .onScrollVisibilityChange(threshold: 0.2) { isVisible in
            playing = isVisible
        }
    }
}
```

When the view appears on-screen, the action will be called if the threshold
has already been reached.

---

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)