UIRefreshcontrol jitters when pulled down and held

后端 未结 7 561
野趣味
野趣味 2021-01-01 23:21

I have created a UIRefreshcontrol in my tableviewcontroller as follows in the viewdidload method :

    refresh = [UIRefreshControl.alloc init];
    refresh.a         


        
相关标签:
7条回答
  • 2021-01-01 23:57

    Just add tableView.alwaysBounceVertical = YES after your [refresh endRefreshing] so table will bounce to top after the refresh control ended its animation.

    0 讨论(0)
  • 2021-01-01 23:58

    So I just came across this same problem, and I came up with a solution. Basically, if you pull your tableView down far enough and hold it, the ValueChanged control event will fire before the user releases the touch. If you refresh your data and reload the tableView at this point, the table will jump up.

    To combat this, I ended up refreshing the table independently of the ValueChanged event. Instead, I used that event, along with the scrollView delegate methods, to only refresh the table after the user had let go.

    So first, set up your refreshControl in viewDidLoad.

    override func viewDidLoad()
    {
        super.viewDidLoad()
    
        refreshControl = UIRefreshControl()
        refreshControl?.addTarget(self, action: "refreshControlChanged", forControlEvents: UIControlEvents.ValueChanged)
    }
    

    The ValueChanged method is simple. If we've already stopped dragging, which happens after a quick swipe down, just refresh the table using your own custom method.

    internal func refreshControlChanged()
    {
        if !tableView.dragging
        {
            refresh()
        }
    }
    

    Then, you need to implement didEndDragging. If you've pulled down far enough, the refreshControl will be refreshing, so call refresh. Otherwise, you either haven't pulled down far enough, you were dragging on a different part of the table, or you dragged so quickly that the refreshControl ValueChanged event has yet to fire, and it will refresh the table there.

    override func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool)
    {
        if refreshControl?.refreshing == true
        {
            refresh()
        }
    }
    

    And that's it. The table won't get reloaded until after you've stopped dragging it, which avoids the jittery jump that you noticed. I know this is a year old, but I hope this helps anyone else coming across this on Google.

    0 讨论(0)
  • 2021-01-02 00:03

    Usually you use UIRefreshControl to trigger an asynchronous reload operation, and endAnimating should be called after a certain period of time has elapsed. It looks here like the moment the refresh control begins animating, you're ending it immediately. This is probably confusing UIRefreshControl.

    Try calling endAnimating after a period of time has elapsed, or in another runloop cycle (e.g. call it in dispatch_async). There appear to be other problems with your code (for example, your tableView:cellForRowAtIndexPath: is creating cells incorrectly), so there might be other problems lurking in there.

    0 讨论(0)
  • @Devin's answer did help but what completely fixed the issue for me was to make my NavigationBar "Translucent". https://i.stack.imgur.com/TKcdH.png

    Using non translucent NavigationBar causes the tableview to jump up slightly when UIControlEventValueChanged is fired for some reason.

    XCode 10.1

    0 讨论(0)
  • 2021-01-02 00:08

    SWIFT 4:

    In ViewdidLoad()

    someCollectionView or someTableView

    someCollectionView.refreshControl?.addSubview(refreshControl)
    someCollectionView.refreshControl?.sendSubview(toBack: refreshControl)
    

    Worked perfectly for me.

    0 讨论(0)
  • 2021-01-02 00:13

    try changing

    self.refreshControl = refresh;
    

    for

    [self.tableView addSubview:refresh];
    [self.tableView sendSubviewToBack:refresh];
    

    +++++++++ if u have problem with attributedString layout with first refreshControl triggered - add this after adding refreshControl as subview

    dispatch_async(dispatch_get_main_queue(), ^{
        [refreshControl beginRefreshing];
        [refreshControl endRefreshing];
    });
    
    0 讨论(0)
提交回复
热议问题