UIRefreshControl坚持返回前景iOS 10

问题描述 投票:2回答:2

我们在UITableViewController上实现了pull down刷新。对于长时间运行的刷新,如果用户进入主屏幕然后返回到应用程序,UIRefreshControl似乎卡住了 - 它仍然显示但没有旋转。在SO上尝试了许多解决方案,但没有任何效果。

我们的实施:

    //Configure pull to refresh when user "pulls down"
    self.refreshControl?.addTarget(self, action: #selector(NotificationTableViewController.handleRefresh(refreshControl:)), for: UIControlEvents.valueChanged)

    //In handleRefresh we will explicitly start the refresh control if this is a background refresh and not a user initiated pull to refresh 
    refreshControl.beginRefreshing()
    self.tableView.setContentOffset(CGPoint(x: 0, y: -refreshControl.frame.size.height - self.topLayoutGuide.length), animated: true)

    //Then once we have reloaded data we stop the refresh in the same manner for user initiated or background refresh (done on main thread)
    refreshControl.endRefreshing()

我们尝试过的解决方案:

Restarting the refreshing when entering foreground when currently refreshing

if refreshControl!.isRefreshing == true {
     refreshControl!.endRefreshing()
     refreshControl!.beginRefreshing()
     self.tableView.setContentOffset(CGPoint(x: 0, y: - refreshControl!.frame.size.height - self.topLayoutGuide.length), animated: true)
}

...然后,如果我们不应该刷新,以下解决方案是关于结束刷新。我确实尝试了它们,但在我们的情况下,我们应该更新...

Calling endRefreshing() when entering foreground if not refreshing

if refreshControl?.isRefreshing == false {
    refreshControl?.endRefreshing()
}

Sending the refresh control to the back on entering foreground

self.refreshControl?.superview?.sendSubview(toBack: self.refreshControl!)

有没有人有一个适用于iOS 10的修复程序?

ios swift uirefreshcontrol
2个回答
2
投票

通常工作的是to stop the refresh control on background/disappear and start it again on foreground/appear

但即使这样也存在竞争条件的问题:我们在后台加载数据#1,另一个线程#2处理前景/出现处理。如果线程#1由于数据加载完成而停止刷新指示器,同时线程#2尝试检查状态并启动刷新控制,那么我们可以在我们的刷新控制正在旋转但我们的加载数据请求的情况下获得自己已经完成了。我们可以尝试同步所有这些,但这不值得努力......

决定只停止背景刷新控制/消失。如果用户在加载过程中返回到屏幕,我们不打算尝试向用户显示刷新控件。

    if refreshControl!.isRefreshing == true {
        refreshControl!.endRefreshing()
    }

0
投票

如果refreshControl!.isRefreshingfalse但你仍然有这个故障使用这个:

override func viewWillAppear(_ animated: Bool) {
  super.viewWillAppear(animated)

  //fixes bug with refreshControl freezing while switching tabs

  if tableView.contentOffset.y < 0 {
    tableView.contentOffset = .zero
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.