跳转至
Structure

PinnedScrollableViews

A set of view types that may be pinned to the bounds of a scroll view.

Declaration

struct PinnedScrollableViews : OptionSet

Overview

Use this option set with the initializer of one of the 4 lazy grid/stacks and the Section structure to pin a view to the top or bottom of the screen while scrolling:

  1. LazyVStack
  2. LazyHStack
  3. LazyVGrid
  4. LazyHGrid

This structure has 2 static properties: sectionHeaders and sectionFooters. You can specify either one of them, or both.

struct ContentView: View {
    var body: some View {
        ScrollView {
            LazyVStack(pinnedViews: .sectionHeaders) {
                Section(header: Text("\*\*Top half\*\*")) {
                    ForEach(1...50, id: \.self) { number in
                        Text("Row \(number)")
                    }
                }
                Section(header: Text("\*\*Bottom half\*\*")) {
                    ForEach(51...100, id: \.self) { number in
                        Text("Row \(number)")
                    }
                }
            }
        }
    }
}

Availability

iOS 14.0+

macOS 11.0+

tvOS 14.0+

watchOS 7.0+

Topics


Type Alias

ArrayLiteralElement The type of the elements of an array literal.

Element The element type of the option set.

RawValue The raw type that can be used to represent all values of the conforming type.


Instance Property

rawValue The corresponding value of the raw type.


Initializer

init(rawValue:) Creates a new option set from the given raw value.


Type Property

sectionFooters The footer view of each Section will be pinned.

sectionHeaders The header view of each Section will be pinned.