嘿所以我有这个代码,目前使得单元格从页面右侧滑入(当我在重新加载表格数据后调用它),而不是通过它们中的每一个,等待延迟然后做下一步,他们都在延迟计数后同时滑入。
为什么会这样? 我几乎可以肯定这会起作用......
- (void)animate
{
for (UITableViewCell* aCell in [self.tableView visibleCells])
{
[aCell setFrame:CGRectMake(320, aCell.frame.origin.y, aCell.frame.size.width, aCell.frame.size.height)];
[UIView animateWithDuration:0.5 delay:0.5 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
[aCell setFrame:CGRectMake(0, aCell.frame.origin.y, aCell.frame.size.width, aCell.frame.size.height)];}
completion:nil];
}
答案 0 :(得分:2)
我认为你只是不明白延迟和阻塞是如何工作的。让我试着清除这段代码:
[self.tableView visibleCells]
数组[UIView animateWithDuration:...]
方法次数,visibleCells
数组中的元素数量(延迟不会冻结您的代码)visibleCells
有多少元素对于您来说,最简单的解决方案是在任何数组中保存可见单元格,然后使用参数调用动画方法 - 您将在此方法中设置动画的索引。在完成块中调用下一个动画。这是代码示例:
- (void)animate:(NSInteger)index {
if (visibaleCells.count <= index) {
return;
}
[UIView animateWithDuration:0.5 delay:0.5 options:0 animations:^{
[visibaleCells[index] setFrame:CGRectMake(0, aCell.frame.origin.y, aCell.frame.size.width, aCell.frame.size.height)];
} completion:^(BOOL finished) {
[self animate:index + 1];
}];
}