One Logo Pool Ball
SwiftUI · IOS API REFERENCE

ScrollViewReader

struct · iOS 14.0+ · SDK 27.1

@frozen nonisolated struct ScrollViewReader<Content> where Content : View

A view that provides programmatic scrolling, by working with a proxy to scroll to known child views. The scroll view reader's content content builder receives a ``ScrollViewProxy`` instance; you use the proxy's ``ScrollViewProxy/scrollTo(_:anchor:)`` to perform scrolling. The following example creates a ``ScrollView`` containing 100 views that together display a color gradient. It also contains two buttons, one each at the top and bottom. The top button tells the ``ScrollViewProxy`` to scroll to the bottom button, and vice versa. @Namespace var topID @Namespace var bottomID var body: some View { ScrollViewReader { proxy in ScrollView { Button("Scroll to Bottom") { withAnimation { proxy.scrollTo(bottomID) } } .id(topID) VStack(spacing: 0) { ForEach(0..<100) { i in color(fraction: Double(i) / 100) .frame(height: 32) } } Button("Top") { withAnimation { proxy.scrollTo(topID) } } .id(bottomID) } } } func color(fraction: Double) -> Color { Color(red: fraction, green: 1 - fraction, blue: 0.5) } ![A scroll view, with a button labeled "Scroll to Bottom" at top. Below this, a series of vertically aligned rows, each filled with a color, that are progressing from green to red.](SwiftUI-ScrollViewReader-scroll-to-bottom-button.png) > Important: You may not use the ``ScrollViewProxy`` during execution of the `content` content builder; doing so results in a runtime error. Instead, only actions created within `content` can call the proxy, such as gesture handlers or a view's `onChange(of:perform:)` method.

Members (0)

This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.

Skipped declarations

3 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

ScrollViewReader.content

closure property answers its caller

ScrollViewReader.init(content:)

callback cannot propagate synchronous failure

ScrollViewReader.body

This protocol needs associated types that cannot yet cross the bridge.

All SwiftUI types →