自定义的UITableViewCell高度产生不当动画 [英] Custom UITableViewCell height yields improper animation

查看:196
本文介绍了自定义的UITableViewCell高度产生不当动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在与以44pts持有大部分标准尺寸单元的UITableView工作。然而,有一对夫妇是较大的,大约160pts

I currently am working with a uitableview that holds mostly standard size cells at 44pts. However, there are a couple that are larger, about 160pts.

在这种情况下,有2个排在44pts高度,具有较大160pts行被下方插入,在该节索引2

In this instance, there are 2 rows at 44pts height, with the larger 160pts row being inserted below, at index 2 in the section.

删除通话:

- (void)removeRowInSection:(TableViewSection *)section atIndex:(NSUInteger)index {
    NSUInteger sectionIndex = [self.sections indexOfObject:section];

    NSIndexPath *removalPath = [NSIndexPath indexPathForRow:index inSection:sectionIndex];

    [self.tableView beginUpdates];
    [self.tableView deleteRowsAtIndexPaths:@[removalPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    [self.tableView endUpdates];
}

代表电话:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    TableViewSection *section = [self sectionAtIndex:indexPath.section];

    return [section heightForRowAtIndex:indexPath.row];
}

部分调用:

- (NSInteger)heightForRowAtIndex:(NSInteger)index {
    StandardCell *cell = (StandardCell *)[self.list objectAtIndex:index];

    return cell.height;
}

细胞电话:

- (CGFloat)height {
    return 160;
}

有什么我困惑的是当我从表中删除较大的行后,便开始制作动画,移动上面行下方。但是,当他们到达某一点,关于通过动画的方式的1/4,它们就会消失整理动画代替。

What has me confused is when I remove the larger rows from the table, they start to animate, moving underneath the row above. But when they get to a certain point, about a 1/4 of the way through the animation, they disappear instead of finishing the animation.

这似乎是表动画与它只有44pts,那么一旦它到达的地方44pts是行的上方,它就会从表中删除下方的点的概念行。有什么细节我忽略了,这将使表中的正确概念来自动制作行去除?

It seems like the table animates the row with the notion that it's only 44pts, then once it's reached the point where 44pts are underneath the row above, it gets removed from the table. What detail have I overlooked that will give the table the correct notion to automatically animate the row removal?

感谢您的帮助。

更新:
我试着注释掉高度以上功能(这将覆盖44返回默认值)。这将导致没有跳过适当动画。 FWIW

Update: I tried commenting out the height function above (which overrides the default that returns 44). This results in a proper animation with no skips. FWIW

推荐答案

要解决这个问题的一个方法是只在删除前下降到44动画行的高度:

One way to solve this is to animate the row height down to 44 just before deleting:

//mark index paths being deleted and trigger `contentSize` update
self.indexPathsBeingDeleted = [NSMutableArray arrayWithArray:@[indexPath]];
[tableView beginUpdates];
[tableView endUpdates];

//delete row
[self.tableView deleteRowsAtIndexPaths:@[removalPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView endUpdates];

然后在你的 heightForRowAtIndexPath

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.indexPathsBeingDeleted containsObject:indexPath]) {
        //return normal height if cell is being deleted
        [self.indexPathsBeingDeleted removeObject:indexPath];
        return 44;
    }
    if (<test for tall row>) {
        return 160;
    }
    return 44;
}

还有簿记正在进行跟踪的指数路径一点点被删除。可能有简洁的方式来做到这一点。这只是浮现在脑海的第一件事。这里有一个工作示例项目

这篇关于自定义的UITableViewCell高度产生不当动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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