如何解决为什么下拉刷新不适用于滚动视图
为什么会出现这个问题?
override func viewDidLoad() {
super.viewDidLoad()
scrollview.alwaysBounceVertical = true
scrollview.bounces = true
refreshControl = UIRefreshControl()
refreshControl.addTarget(self,action: #selector(didPullToRefresh),for: .valueChanged)
self.scrollview.addSubview(refreshControl)
}
@objc func didPullToRefresh() {
print("Refersh")
// For End refrshing
refreshControl.endRefreshing()
}
解决方法
iOS 10 > UIScrollView has a refreshControl property。当您创建 UIRefereshControl 并将其分配给此属性时,将出现此 refreshControl。 无需将 UIRefereshControl 添加为滚动子视图。
func configureRefreshControl () {
// Add the refresh control to your UIScrollView object.
myScrollingView.refreshControl = UIRefreshControl()
myScrollingView.refreshControl?.addTarget(self,action:
#selector(handleRefreshControl),for: .valueChanged)
}
@objc func handleRefreshControl() {
// Update your content…
// Dismiss the refresh control.
DispatchQueue.main.async {
self.myScrollingView.refreshControl?.endRefreshing()
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。