Ios 当我在UIScrollView上下拉刷新时,需要下拉到屏幕中间
我有一个函数:didPullToRefresh。为了启动这个功能,我必须将UIScrollView一直拉到屏幕中间。有没有一种方法可以只通过将屏幕向下拉50像素来刷新我想要刷新的数据?谢谢 以下是我当前运行的代码:Ios 当我在UIScrollView上下拉刷新时,需要下拉到屏幕中间,ios,swift,xcode,uiscrollview,refresh,Ios,Swift,Xcode,Uiscrollview,Refresh,我有一个函数:didPullToRefresh。为了启动这个功能,我必须将UIScrollView一直拉到屏幕中间。有没有一种方法可以只通过将屏幕向下拉50像素来刷新我想要刷新的数据?谢谢 以下是我当前运行的代码: var refreshControl: UIRefreshControl! override func viewDidLoad() { super.viewDidLoad() scrollView.alwaysBounceVertical = true scro
var refreshControl: UIRefreshControl!
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()
}
不要将目标添加到刷新控件。只需将子视图添加到scrollview。在viewDidLoad中:
scrollView.alwaysBounceVertical = true
scrollView.bounces = true
scrollView.delegate = self
refreshControl = UIRefreshControl()
self.scrollView.addSubview(refreshControl)
将scrollview委托设置为self。并实现以下scrollview委托方法:
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if scrollView.contentOffset.y <= -50 {
refreshControl.beginRefreshing()
print("Start Refresh Service")
}
}
写入refreshControl?.EndRefresh on refresh service finish。是否有办法做到这一点,但要在加载时延迟反弹?如下所示:DispatchQueue.main.asyncAfterdeadline:。现在+1.0{//在此处编写代码。}您可以编辑上面的代码,显示代码的去向吗?