滚动时滑入UITableViewCells

Ale*_*Cio 3 objective-c uitableview ios

我有一个UITableView并且想要动画再次出现的行.我也想在动画之间切换,有些小区应该得到UITableViewRowAnimationLeft和其他人一样UITableViewRowAnimationRight.但我不知道如何用我的实现这个功能UITableViewController.我尝试将以下代码行插入cellForRowAtIndexPath:

[self.tableView beginUpdates];
NSArray *updatePath = [NSArray arrayWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:updatePath 
                      withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)

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

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

Tim*_*ose 8

一旦表开始在屏幕上显示单元格的过程,我不认为你会成功重新加载行.reloadRowsAtIndexPath通常导致cellForRowAtIndexPath被调用,所以我很惊讶你没有进入无限循环.相反,它似乎进入了糟糕的状态.

我的建议是在这种情况下做自己的动画,操纵单元格的转换属性willDisplayCell.你可以这样做:

- (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;
        }];
    }
}
Run Code Online (Sandbox Code Playgroud)

您需要为"应该动画单元格"提供逻辑 - 您可能不希望在初始加载时为单元设置动画.