本文介绍了UIRefreshControl endRefreshing不流畅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的数据加载完毕并且我的tableView已经重新加载时,我在刷新控件上调用endRefreshing,然后从其加载状态跳转并消失 - 我怎么能实现一个平滑的动画,当你将刷新控件滑落时它是完整的吗?

When my data has finished loading and my tableView has been reloaded, I call endRefreshing on my refresh control, it then 'jumps' from its loading state and disappears - how can I implement a smooth animation that slides the refresh control away when it is complete?

推荐答案

我正在添加一个新答案,因为唯一一个解释不是很精确。这可能对评论来说太过分了。

I'm adding a new answer since the only one is not very precise in explanation. And this would probably be too much for comments.

是对的。但提到的原因是错误的。

The solution by Halpo is correct. But the reason mentioned is wrong.

调用 - [NSObject(NSDelayedPerforming)performSelector:withObject:afterDelay:] 保证调用将在下一个runloop迭代中执行。

Calling -[NSObject (NSDelayedPerforming) performSelector:withObject:afterDelay:] guarantees the call to be performed in the next runloop iteration.

所以这不起作用,因为有一个小的延迟,但你将它移动到下一个循环。

So this does not work, because there is a small delay, but you're moving it to the next loop.

实际上,您可以将延迟减少到 0.0 ,它仍然有效。此外,更正确(就使用对象意味着实现某些目标,而不是更好的结果)实现是可能的。

Actually you sh/could decrease the delay to 0.0 and it would still work. Also, a more correct (in terms of using the object meant to achieve something, not better in outcome) implementation is possible.

以下是各种代码片段:

Here are the various code snippets for that:

// SOLUTION I

[[self tableView] reloadData];
[[self refreshControl] performSelector:@selector(endRefreshing) withObject:nil afterDelay:0.0];

// SOLUTION II (semantically correct)

[[self tableView] reloadData];
[[NSOperationQueue currentQueue] addOperationWithBlock:^{
    [[self refreshControl] endRefreshing];
}];

// SOLUTION III (GCD)

dispatch_async(dispatch_get_main_queue(), ^{
    [[self refreshControl] endRefreshing];
}];

编辑

指出,你也可以使用GCD。我很喜欢GCD,但我我认为,解决方案II对于最新情况是最具描述性的。而且,GCD不是很客观C-ish,所以我个人宁愿坚持我的解决方案。

As johann-fradj pointed out, you could also use GCD. I do like GCD a lot, but I think, solution II is most descriptive about whats going on. Also, GCD is not very Objective-C-ish, so I'd personally rather stick to my solution.

这篇关于UIRefreshControl endRefreshing不流畅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 21:09