SwiftUI Introspect 库拉取刷新问题
我想在 SwiftUi 的滚动视图中实现拉动刷新。所以我一直在尝试 Introspect 库来使用其 .introspectScrollView
和使用刷新控制器。 但我遇到了一个问题,刷新进度旋转器立即隐藏在我的末端。所以我想知道如何继续显示刷新微调器直到数据加载。
另请注意,我没有使用列表,因为 ScrollView 中有子视图,所以我仍在使用 ScrollView。
我的代码是 -
ScrollView{
//subView1
//subView2
}.introspectScrollView { scrollView in
let control = UIRefreshControl()
control.addTarget(viewModel, action: #selector(viewModel.loadData1), for: .valueChanged)
scrollView.refreshControl = control
viewModel.isRefreshed = {
control.endRefreshing()
}
}
//In view model
var isRefreshed: (() -> ())?
func loadData1(){
// load data 1
loadData2()
}
func loadData2(){
//load data2
isRefreshed?()
}
I want to implement pull to refresh in my scrollview in SwiftUi. So I have been trying Introspect library to use its .introspectScrollView
and use refresh controller.
But I have been getting an issue with it, the refresh progress spinner immediately gets hidden in my end. So I wanted to know how to keep showing the refresh spinner until the data loads.
Also please note I am not using list as I have subViews inside the ScrollView, so I am still using ScrollView.
My code is -
ScrollView{
//subView1
//subView2
}.introspectScrollView { scrollView in
let control = UIRefreshControl()
control.addTarget(viewModel, action: #selector(viewModel.loadData1), for: .valueChanged)
scrollView.refreshControl = control
viewModel.isRefreshed = {
control.endRefreshing()
}
}
//In view model
var isRefreshed: (() -> ())?
func loadData1(){
// load data 1
loadData2()
}
func loadData2(){
//load data2
isRefreshed?()
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试 SwiftUIRefresh 包,其中包括 Introspect 和 SwiftuiRefresh 包。因此,将
https://github.com/timbersoftware/SwiftUIRefresh.git
链接添加到您的包中,并使用以下源代码:https://github.com/siteline/SwiftUIRefresh
You could try the SwiftUIRefresh package, that includes both Introspect and SwiftuiRefresh packages. So, add
https://github.com/timbersoftware/SwiftUIRefresh.git
link to your package and use this likeSource code from: https://github.com/siteline/SwiftUIRefresh