TechnologiesSwiftUIScrolling

ScrollInputKind struct

iOSmacOStvOSwatchOSvisionOSiOS 18.0+✓ renders

Inputs used to scroll views.

How it works

ScrollInputKind is a structure whose constants identify the kind of input that is currently driving a scroll, distinguishing, for example, a precise pointing device from a coarse one. SwiftUI hands you a value of this type when it needs to know how the user is moving content, so you can tailor behavior to the input source rather than treating every scroll the same. Reach for it when a gesture or modifier should respond differently depending on whether the scroll comes from a trackpad, a mouse wheel, or another mechanism, and pair it with the scroll-input modifiers that decide which kinds of input are allowed to act on a particular part of the scroll view.

  1. Identify the input source with the ScrollInputKind constants

    ScrollInputKind exposes named constants that each stand for one category of scrolling input. You compare against these constants to branch on how the user is driving the scroll, keeping decisions about input source in one well-typed place instead of inferring it from raw gesture data.

  2. Scope a kind to a region of the scroll view

    The kind is meaningful relative to a specific part of the scroll view, such as its content or its indicators. In the example, .scrollIndicators is the region being targeted, so the input kind governs how that region responds rather than the whole view at once.

  3. Apply it through a scroll-input modifier

    You wire ScrollInputKind into a view hierarchy through a scroll-input modifier that takes the behavior and the region it applies to. Here scrollInputBehavior(.enabled, for: .scrollIndicators) is the attachment point: it declares which inputs are honored for the indicators, and ScrollInputKind is the vocabulary that describes those inputs.

  4. Toggle the behavior per kind

    Each region can have its scroll input enabled or disabled, letting you opt a kind in or out for that target. The .enabled value passed to scrollInputBehavior turns the indicator-driven input on, and switching it would suppress that input for the same region.

  5. Let SwiftUI route the live input

    Once configured, SwiftUI matches the user's actual input against the kinds you allowed and routes scrolling accordingly. The ScrollView and its VStack of Text rows simply provide the surface; ScrollInputKind is what classifies the input that moves them.

Try it — Change .enabled in scrollInputBehavior(.enabled, for: .scrollIndicators) to .disabled and watch the scroll indicators stop responding to that input kind.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

ScrollInputKind.swift
struct ScrollInputKindDemo: View {
    var body: some View {
        ScrollView {
            VStack(spacing: 12) {
                ForEach(1..<13) { i in
                    Text("Row \(i)")
                        .frame(maxWidth: .infinity)
                        .padding()
                        .background(.blue.opacity(0.15))
                        .clipShape(RoundedRectangle(cornerRadius: 8))
                }
            }
            .padding()
        }
        .scrollInputBehavior(.enabled, for: .scrollIndicators)
    }
}
Live preview
Row 1 Row 2 Row 3 Row 4 Row 5 Row 6 Row 7 Row 8 Row 9 Row 10 Row 11 Row 12
Row 1 Row 2 Row 3 Row 4 Row 5 Row 6 Row 7 Row 8 Row 9 Row 10 Row 11 Row 12
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →