Prefer Large Titles and RefreshControl not working well

后端 未结 11 2142
野性不改
野性不改 2020-12-29 05:09

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 eve

相关标签:
11条回答
  • 2020-12-29 05:39

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

    tableView.contentInsetAdjustmentBehavior = .always

    0 讨论(0)
  • 2020-12-29 05:40

    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.

    0 讨论(0)
  • 2020-12-29 05:42

    It seems there are a lot of different causes that could make this happen, for me I had a TableView embedded within a ViewController. I set the top layout guide of the tableview to the superview with 0. After all of that still nothing until I wrapped my RefreshControl end editing in a delayed block:

    DispatchQueue.main.async {
       if self.refreshControl.isRefreshing {
           DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
                self.refreshControl.endRefreshing()
           })
       }
    }
    
    0 讨论(0)
  • 2020-12-29 05:44

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

    0 讨论(0)
  • 2020-12-29 05:46

    I was facing the same issue for very long, the only working solution for me was adding refresh control to the background view of tableview.

    tableView.backgroundView = refreshControl
    
    0 讨论(0)
  • 2020-12-29 05:50

    Short Answer

    I fixed this by delaying calling to API until my collection view ends decelerating

    Long Answer

    I notice that the issue happens when refresh control ends refreshing while the collection view is still moving up to its original position. Therefore, I delay making API call until my collection view stops moving a.k.a ends decelerating. Here's a step by step:

    1. Follow Bruno's suggestion
    2. If you set your navigation bar's translucent value to false (navigationBar.isTranslucent = false), then you will have to set extendedLayoutIncludesOpaqueBars = true on your view controller. Otherwise, skip this.
    3. Delay api call. Since I'm using RxSwift, here's how I do it.
    collectionView.rx.didEndDecelerating
        .map { [unowned self] _ in self.refreshControl.isRefreshing }
        .filter { $0 == true }
        .subscribe(onNext: { _ in
            // make api call
        })
        .disposed(by: disposeBag)
    
    1. After API completes, call to
    refreshControl.endRefreshing()
    

    Caveat

    Do note that since we delay API call, it means that this whole pull-to-refresh process is not as quick as it could have been done without the delay.

    0 讨论(0)
提交回复
热议问题