<!--
{
  "availability" : [
    "iOS: 27.3.0 -",
    "iPadOS: 27.3.0 -",
    "macCatalyst: 27.3.0 -",
    "macOS: 27.3.0 -",
    "visionOS: 27.3.0 -",
    "watchOS: 27.3.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/scrollGestureAxisLock(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE21scrollGestureAxisLockyQrAA06ScrollefG0VF"
  },
  "title" : "scrollGestureAxisLock(_:)"
}
-->

# scrollGestureAxisLock(_:)

Sets whether scrollable views within this view lock each scroll
gesture to its predominant axis.

```
@MainActor @preconcurrency func scrollGestureAxisLock(_ lock: ScrollGestureAxisLock) -> some View
```

## Parameters

`lock`

The locking behavior to apply.

## Return Value

A view that uses the specified locking behavior.

## Discussion

Use [`disabled`](/documentation/SwiftUI/ScrollGestureAxisLock/disabled) so that people can pan diagonally
across content like a canvas or a map. Use
[`directional`](/documentation/SwiftUI/ScrollGestureAxisLock/directional) to keep scrolling aligned
vertically or horizontally, as in a spreadsheet.

For example, this scroll view lets people pan a floor plan freely
in any direction:

```
ScrollView([.horizontal, .vertical]) {
    Image("FloorPlan")
}
.scrollGestureAxisLock(.disabled)
```

The locking behavior applies to the scroll views in this view hierarchy
that are configured to scroll along both axes. Scroll views configured
to scroll along a single axis, such as a [`List`](/documentation/SwiftUI/List), ignore the locking
behavior and pass it to the scroll views they contain. A scroll view
configured to scroll along both axes doesn’t pass the locking behavior
to nested child scroll views.

Pass [`automatic`](/documentation/SwiftUI/ScrollGestureAxisLock/automatic) to use the platform’s default
behavior.

---

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)