Prefer Large Titles and RefreshControl not working

2020-06-01 06:45发布

I am using this tutorial to implement a pull-to-refresh behavior with the RefreshControl. I am using a Navigation Bar. When using normal titles everything works good. But, when using "Prefer big titles" it doesn't work correctly as you can see in the following videos. Anyone knows why? The only change between videos is the storyboard check on "Prefer Large Titles".

With "Prefer big titles" With normal title

9条回答
我欲成王,谁敢阻挡
2楼-- · 2020-06-01 06:48

At the end what worked for me was:

  • In order to fix the RefreshControl progress bar disappearing bug with large titles:

    self.extendedLayoutIncludesOpaqueBars = true
    
  • In order to fix the list offset after refreshcontrol.endRefreshing():

    let top = self.tableView.adjustedContentInset.top
    let y = self.refreshControl!.frame.maxY + top
    self.tableView.setContentOffset(CGPoint(x: 0, y: -y), animated:true)
    
查看更多
Emotional °昔
3楼-- · 2020-06-01 06:48

If you were using tableView.tableHeaderView = refreshControl or tableView.addSubView(refreshControl) you should try using tableView.refreshControl = refreshControl

查看更多
放我归山
4楼-- · 2020-06-01 06:53

I've faced the same problem. Call refreshControl endRefreshing before calling further API.

refreshControl.addTarget(controller, action: #selector(refreshData(_:)), for: .valueChanged)

@objc func refreshData(_ refreshControl: UIRefreshControl) {
        refreshControl.endRefreshing()
        self.model.loadAPICall {
            self.tableView.reloadData()
        }
    }
查看更多
再贱就再见
5楼-- · 2020-06-01 06:55

I had this issue too, and i fixed it by embedded my scrollView (or tableView \ collectionView) inside stackView, and it's important that this stackView's top constraint will not be attached to the safeArea view (all the other constraints can). the top constraint should be connect to it's superview or to other view.

查看更多
闹够了就滚
6楼-- · 2020-06-01 06:57

Problem can be solved if add tableview or scroll view as root view in UIViewController hierarchy (like in UITableViewController)

override func loadView() {
    view = customView
}

where customView is UITableView or UICollectionView

查看更多
Explosion°爆炸
7楼-- · 2020-06-01 07:05

The only working solution for me is combining Bruno's suggestion with this line of code:

tableView.contentInsetAdjustmentBehavior = .always

查看更多
登录 后发表回答