xcode UIRefreshController 结束动画问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27280544/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIRefreshController Ending Animation Issue
提问by uhfocuz
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()
?
当我调用self.refreshControl.endRefreshing()
它时,它会像它应该的那样将 tableView 捕捉回它的原始位置。我应该如何对其进行动画处理,以使其流畅地返回到原来的位置endRefreshing()
?
回答by rowwingman
Try this
尝试这个
[CATransaction begin];
[CATransaction setCompletionBlock:^{
// reload tableView after refresh control finish refresh animation
[self.tableView reloadData];
}];
[self.refreshControl endRefreshing];
[CATransaction commit];
回答by uhfocuz
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.
对于遇到此问题的任何人,您必须endRefreshing
在重新加载表数据之前调用您的方法。否则,当表更新时,它会覆盖刷新器并导致它看起来有问题。
回答by Devin
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!
在界面生成器中启用它解决了我的问题。如果您已经尝试了其他所有方法,请检查您的故事板!
回答by Lucas Chwe
// stop refreshing
[self.refreshControl endRefreshing];
// update tableview
[self.tableview performSelector:@selector(reloadData) withObject:nil afterDelay:.3];
回答by Eytan
I've run into this issue as well. For endRefreshing()
The documentation states:
我也遇到过这个问题。对于endRefreshing()
文档指出:
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 动画块中,过渡变得平滑:
UIView.animateWithDuration(0.5) {
self.refreshControl.endRefreshing()
}
回答by ibrahimyilmaz
This works for me with Swift 2
这对我有用 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)
}
回答by Mikael
In Swift 3 iOS 10, I got a similar approach as ibrahimyilmaz and here it is:
在 Swift 3 iOS 10 中,我得到了与 ibrahimyilmaz 类似的方法,这里是:
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.
起初,我按照许多线程中的建议调度了 endRefreshing,但实际上,它的另一种方式对我有用。
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.
附加信息:此代码在 location:didChange: 委托中执行,而不是在 viewDidLoad 或 viewWillAppear 中执行。通过其他线程,当您尝试结束刷新并尝试同时显示弹出窗口时,Apple SDK 中似乎存在问题。