I'm trying to make my ScrollView:
- Not bounce when the content is smaller than the screen
- Bounce when the content overflows the screen
Here's my code:
struct ContentView: View {
init() {
UIScrollView.appearance().alwaysBounceVertical = false
}
var body: some View {
ScrollView {
Rectangle()
.fill(Color.blue)
.frame(height: 300) /// is smaller than the screen
.padding()
}
}
}
I tried setting UIScrollView.appearance().alwaysBounceVertical = false, but the scroll view still bounces:
If I do UIScrollView.appearance().bounces = false, it stops bouncing. However, if I make the rectangle taller than the screen, it also stops bouncing (which I don't want).
How can I disable bouncing, but only when the content is smaller than scroll view's bounds?


