<!--
{
  "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/AnyScrollTargetBehavior",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI23AnyScrollTargetBehaviorV"
  },
  "title" : "AnyScrollTargetBehavior"
}
-->

# AnyScrollTargetBehavior

A type-erased scroll target behavior.

```
@frozen struct AnyScrollTargetBehavior
```

## Overview

Provide this to the [`scrollTargetBehavior(_:)`](/documentation/SwiftUI/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)
}
```

## Topics

### Initializers

[`init(some ScrollTargetBehavior)`](/documentation/SwiftUI/AnyScrollTargetBehavior/init(_:))

Creates a new type-erase scroll target behavior.

### Instance Properties

[`var base: any ScrollTargetBehavior`](/documentation/SwiftUI/AnyScrollTargetBehavior/base)

The type-erased scroll target behavior.

## Relationships

### Conforms To

[`ScrollTargetBehavior`](/documentation/SwiftUI/ScrollTargetBehavior)

---

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)