滚动时在UITableViewCells中滑动

我有一个UITableView并想要animation行将再次出现。 我也想切换animation,一些单元格应该得到UITableViewRowAnimationLeft和其他的UITableViewRowAnimationRight 。 但我不知道如何用我的UITableViewController实现这个function。 我试图插入以下代码行到cellForRowAtIndexPath

 [self.tableView beginUpdates]; NSArray *updatePath = [NSArray arrayWithObject:indexPath]; [self.tableView reloadRowsAtIndexPaths:updatePath withRowAnimation:UITableViewRowAnimationLeft]; [self.tableView endUpdates]; 

而不是在细胞中滑动,细胞的顺序改变或者其中一些出现两次。 我也尝试在创build单元格后插入这些行。

 if (cell == nil) { ... } else { [self.tableView beginUpdates]; NSArray *updatePath = [NSArray arrayWithObject:indexPath]; [self.tableView reloadRowsAtIndexPaths:updatePath withRowAnimation:UITableViewRowAnimationLeft]; [self.tableView endUpdates]; 

一旦表格已经开始在屏幕上显示单元格的过程,我不认为你会成功地重新加载行。 reloadRowsAtIndexPath通常会导致cellForRowAtIndexPath被调用,所以我很惊讶你没有进入一个无限循环。 反而看起来,桌子正在进入一个糟糕的状态。

我的build议是在这种情况下做自己的animation,在willDisplayCell操作单元格的transform属性。 你可以做这样的事情:

 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if (<should animate cell>) { CGFloat direction = <animate from right> ? 1 : -1; cell.transform = CGAffineTransformMakeTranslation(cell.bounds.size.width * direction, 0); [UIView animateWithDuration:0.25 animations:^{ cell.transform = CGAffineTransformIdentity; }]; } } 

你需要提供逻辑“应该有animation细胞” – 你可能不想在初始加载时animation细胞。