One Logo Pool Ball
SwiftUI · IOS API REFERENCE

AnyScrollTargetBehavior

struct · iOS 18.0+ · SDK 27.1

@frozen struct AnyScrollTargetBehavior

A type-erased scroll target behavior. Provide this to the ``View/scrollTargetBehavior(_:)`` modifier. When the underlying behavior changes, the scroll view to which this behavior applies will be updated. Use this to dynamically control the scroll target behavior at runtime. For example, you could provide a paging behavior in compact size classes and a view aligned behavior otherwise. @Environment(\.horizontalSizeClass) var sizeClass var body: some View { ScrollView { ... } .scrollTargetBehavior(scrollTargetBehavior) } var scrollTargetBehavior: some ScrollTargetBehavior { sizeClass == .compact ? AnyScrollTargetBehavior(.paging) : AnyScrollTargetBehavior(.viewAligned) }

Members (4)

method · iOS 18.0+

updateTarget

TypeScript
updateTarget(target: _SwiftUICore_ScrollTarget, context: ScrollTargetBehaviorContext): { $ret: null; $out: { "target": _SwiftUICore_ScrollTarget } }
Swift declaration
func updateTarget(_ target: inout ScrollTarget, context: AnyScrollTargetBehavior.TargetContext)

Updates the proposed target that a scrollable view should scroll to. The system calls this method in two main cases: - When a scroll gesture ends, it calculates where it would naturally scroll to using its deceleration rate. The system provides this calculated value as the target of this method. - When a scrollable view's size changes, it calculates where it should be scrolled given the new size and provides this calculates value as the target of this method. You can implement this method to override the calculated target which will have the scrollable view scroll to a different position than it would otherwise.

Omit the output parameters from the call. The result contains $ret and $out, with target inside $out.

method · iOS 18.4+

properties

TypeScript
properties(context: ScrollTargetBehaviorPropertiesContext): ScrollTargetBehaviorProperties
Swift declaration
func properties(context: AnyScrollTargetBehavior.PropertiesContext) -> AnyScrollTargetBehavior.Properties

Properties of this behavior

get · iOS 18.0+

base

TypeScript
get base(): SDKHandle
Swift declaration
var base: any ScrollTargetBehavior

The type-erased scroll target behavior.

set · iOS 18.0+

base

TypeScript
set base(value: SDKHandle)
Swift declaration
var base: any ScrollTargetBehavior

The type-erased scroll target behavior.

Skipped declarations

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

AnyScrollTargetBehavior.init(_:)

This parameter hides a concrete Swift type.

All SwiftUI types →