One Logo Pool Ball
SwiftUI · IOS API REFERENCE

ScrollViewProxy

struct · iOS 14.0+ · SDK 27.1

struct ScrollViewProxy

A proxy value that supports programmatic scrolling of the scrollable views within a view hierarchy. You don't create instances of `ScrollViewProxy` directly. Instead, your ``ScrollViewReader`` receives an instance of `ScrollViewProxy` in its `content` content builder. You use actions within this content builder, such as button and gesture handlers or the ``View/onChange(of:perform:)`` method, to call the proxy's ``ScrollViewProxy/scrollTo(_:anchor:)`` method.

Members (1)

method · iOS 14.0+

scrollTo

TypeScript
scrollTo(id: number, anchor?: (_SwiftUICore_UnitPoint) | null): void
Swift declaration
func scrollTo<ID>(_ id: ID, anchor: UnitPoint? = nil) where ID : Hashable

Scans all scroll views contained by the proxy for the first with a child view with identifier `id`, and then scrolls to that view. If `anchor` is `nil`, this method finds the container of the identified view, and scrolls the minimum amount to make the identified view wholly visible. If `anchor` is non-`nil`, it defines the points in the identified view and the scroll view to align. For example, setting `anchor` to ``UnitPoint/top`` aligns the top of the identified view to the top of the scroll view. Similarly, setting `anchor` to ``UnitPoint/bottom`` aligns the bottom of the identified view to the bottom of the scroll view, and so on. - Parameters: - id: The identifier of a child view to scroll to. - anchor: The alignment behavior of the scroll action.

Skipped declarations

No declarations were skipped in this snapshot.

All SwiftUI types →