当UITableView滚动时,UITableViewCell动画停止 [英] UITableViewCell animations stop when UITableView is scrolling

查看:1491
本文介绍了当UITableView滚动时,UITableViewCell动画停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的应用程序中创建一个事件倒计时场景,该场景使用UITableViewController来显示将来发生的事件列表。在每个单元格中,我都有一个倒数计时器,可以计算事件发生前的时间。

I am making an 'event countdown' scene in my app that uses a UITableViewController to show a list of events that are happening in the future. In each cell I have a countdown timer that counts down the time until the event takes place.

我想为这些倒计时字段设置动画,以便实时记下这些字段。我已经实现了这个动画,但问题是当用户滚动uitableview时动画暂停,直到用户释放滚动。我希望动画即使在滚动时也能继续。

I want to animate these countdown fields so they tick down in real time. I have achieved this animation already, but the problem is that when the user scrolls the uitableview the animation pauses until the user releases the scroll. I want the animations to continue even when scrolling.

我动画的方式是每隔0.25秒在NSTimer上调用[self.tableview reloadData](我知道这个不是最有效的方法 - 这更多地测试动画本身)。我也尝试在UITableViewCell本身内运行NSTimer调用视图更新 - 但滚动时仍然会暂停动画。

The way I'm animating is by calling [self.tableview reloadData] on a NSTimer every 0.25s (I know this isn't the most efficient method - this was more testing the animation itself). I have also tried running an NSTimer calling view updates within the UITableViewCell itself - but still have the animation pauses when scrolling.

任何人都知道调用动画的设置或替代方法滚动时会保持这种状态吗?

Anyone know a setting or alternative way of calling the animation that will keep it going whilst scrolling?

推荐答案

在UIScrollViews的同一问题上进行了更多的搜索,这让我发表了这篇文章我的自定义UI元素......

Some more searching on this same issue for UIScrollViews yielded led me to this postMy custom UI elements...

基本上发生的事情是我正在使用的NSTimer在滚动时没有被更新,因为滚动阻止了它自己的运行循环模式之外的所有内容。修复是将动画NSTimer添加到滚动使用的相同运行循环模式:NSRunLoopCommonModes

Basically what is happening is that the NSTimer I was using was not being updated when scrolling because scrolling blocks everything outside of its own run loop mode. The fix is to add the animation NSTimer to the same run loop mode that is used by scrolling: NSRunLoopCommonModes

以下是如何在代码中执行此操作:

Here's how to do it in code:

NSTimer *timer = [NSTimer timerWithTimeInterval:0.25 self selector:@selector(updateCountdownLabels) userInfo:nil repeats:YES]; 
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

这篇关于当UITableView滚动时,UITableViewCell动画停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆