Thanks for your answer.
Unfortunately, I'm not sure how to interpret it. Maybe my question was not clear enough and I badly explained what I want.
I don't want to only detect the top of the red Text("0") view (i.e. the top of the scrollView), I want to detect the top/bottom of every red Text("...") view, without the spacing being taken into account.
So when scrolling down, I want the binding to be updated only when a red background is at the top of the visible scroll view. In the example I provide, the binding is updated to 5 soon after I scroll 4, where 5 is at the middle of the screen.
And when scrolling down, I want the binding to be updated only when a red background appears at the top. In my example, the binding is updated to 8 when 9 is still almost at the top of the screen.
The thing I find strange is that setting the binding to 7 scroll at the position I want: just over the red Text("7") view. As if this was considered the top of a target View.
Why scrolling provides a different result? Why would the spacing or margin be taken into account when scrolling but not when specifying manually a position?
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: