UIRefreshController Ending Animation Issue

懵懂的女人 提交于 2020-02-01 04:54:17

问题


When I call for self.refreshControl.endRefreshing() it snaps the tableView back to it original spot like it should. How should I go about animating it so that it fluently returns to its original spot on endRefreshing()?


回答1:


Try this

[CATransaction begin];
[CATransaction setCompletionBlock:^{
    // reload tableView after refresh control finish refresh animation
    [self.tableView reloadData];
}];

[self.refreshControl endRefreshing];
[CATransaction commit];



回答2:


To anyone having this issue, you must call your endRefreshing method before you reload the table data. Otherwise when the table updates it will override the refresher and cause it to look buggy.




回答3:


// stop refreshing
[self.refreshControl endRefreshing];

// update tableview
[self.tableview performSelector:@selector(reloadData) withObject:nil afterDelay:.3]; 



回答4:


I was having this issue and tried every suggestion above (and others from similar threads).

What the problem turned out to be in my case was... I hadn't enabled refreshing in interface builder. I only added the code to create a refresh control and listen for the value changed event. It worked, but was "jumpy" as others have described.

Enabling it in interface builder fixed my problem. If you've tried everything else, check your storyboard!




回答5:


This works for me with Swift 2

if self.refreshControl.refreshing {
     self.refreshControl.endRefreshing()
}

GlobalHelper.setTimeout(0.1, block: {
     self.tableView.reloadData()
})

this is my timeout function:

static func setTimeout(delay:NSTimeInterval, block:()->Void) -> NSTimer {
    return NSTimer.scheduledTimerWithTimeInterval(delay, target: NSBlockOperation(block: block), selector: #selector(NSOperation.main), userInfo: nil, repeats: false)
}



回答6:


I've run into this issue as well. For endRefreshing() The documentation states:

If animations are also enabled, the control is hidden using an animation.

I wrap the call in a UIView animation block and the transition becomes smooth:

UIView.animateWithDuration(0.5) {
    self.refreshControl.endRefreshing()
}



回答7:


In Swift 3 iOS 10, I got a similar approach as ibrahimyilmaz and here it is:

self.refreshControl.endRefreshing()
//Need to dispatch the alertView, otherwise, RefreshControl.endRefreshing() doesn't work.
let when = DispatchTime.now() + 1 
DispatchQueue.main.asyncAfter(deadline: when) { [weak self] in
  self?.showSettingAlertView()
}

At first I was dispatching the endRefreshing as proposed in many threads but in fact it's the other way around that works for me.

Additional info: This code is executed in the location:didChange: delegate, not in viewDidLoad or viewWillAppear. Going through other threads, It seems that there is an issue in the Apple SDK when you try to endRefreshing AND try to show a popup at the same time.



来源:https://stackoverflow.com/questions/27280544/uirefreshcontroller-ending-animation-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!