Bottom-first scrolling in SwiftUI

家住魔仙堡 提交于 2019-12-08 10:55:40

问题


How can I make a SwiftUI List start scrolling from the bottom of the screen (like a chat view)?

Ideally, I want to mimic, e.g. the behavior of iMessage when the list updates, meaning it shifts down if an item is added when the user is at the bottom, but holds it’s position if the user manually scrolled up.

The list is read directly from a binding array, and the order can be reversed if convenient.

@komal pointed out that the UITableView (the backend of List) has an atScrollPosition that should provide this functionality. However, there doesn't seem to be a way to access the underlying view without completely reimplementing List as a UIViewRepresentable, which is easier said than done, considering the standard implementation is completely black-boxed and closed-source.

With that said, I've also posted Access underlying UITableView from SwiftUI List, which, if solved, could serve as an answer to this question.


回答1:


I would suggest that instead of using scrollview, use UITableView as Tablview inherits scroll property of UIScrollview. And you can use "atScrollPosition:UITableViewScrollPositionBottom" to achieve this behavior.



来源:https://stackoverflow.com/questions/58101865/bottom-first-scrolling-in-swiftui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!