An example of usage of the SolidScrollView/
source link: https://gist.github.com/edudnyk/08d82f3579bb04b46e05d52170828e5e
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Instantly share code, notes, and snippets.
struct ContentView: View { var config = ScrollViewConfig() @State var scrollViewProxy: SolidScrollViewProxy?
var body: some View { VStack(spacing: 0) { SolidScrollView(config) { VStack(spacing: 0) { Color.red.frame(height: 200) Color.green.frame(height: 200) Color.blue.frame(height: 200) Color.black.frame(height: 200) } } Button("Scroll to 3/4 of the content height via proxy") { guard let scrollViewProxy = scrollViewProxy else { return } let contentOffset = CGPoint(x: 0, y: min(scrollViewProxy.contentSize.height * 3.0 / 4, scrollViewProxy.maxContentOffset.y)) scrollViewProxy.setContentOffset(contentOffset, animated: true, completion: { completed in print("Scrolled via proxy to \(contentOffset)! Completed: \(completed)") }) } } .onPreferenceChange(ContainedScrollViewKey.self) { scrollViewProxy = $0 } } }
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK