1

I’m trying to accomplish this effect from the Apple News app where the header element scrolls out of the view but when it comes back into view it doesn’t bounce. It sticks to the top while the remainder of the scroll view continues to bounce.

Example

Right now, I have my header component as the first element in the scroll view. I can turn bouncing off for the entire scroll view, but that isn’t the effect I’m looking for. I'm using the introspect package to get access to underlying scrollview.

struct TestView: View {
    var body: some View {
        ScrollView {
            VStack { //Header
                Text("Header content")
            }
            .frame(maxWidth: .infinity)
            .padding(16)
            .background(.white)
            
            ForEach(1...100, id: \.self) { value in
                Text(value.stringValue)
            }
        }
        .frame(maxWidth: .infinity)
        .background(.gray)
        .introspectScrollView { scrollView in
            scrollView.bounces = false
        }
    }
}
ShaneP
  • 15
  • 1
  • 5

0 Answers0