RowAnimation在不同的高度单元格下看起来很奇怪 [英] RowAnimation looks weird with different height cells

查看:254
本文介绍了RowAnimation在不同的高度单元格下看起来很奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UITableView上对删除和插入进行动画处理时遇到问题.事实,我有不同的像元高度,现在大约是44.0,大约是135.0.我有uitableviewstylegroup与不同的部分.每个部分的第一行是一个分组行.单击时,我将删除该部分中除分组行之外的所有行.但是,当动画(UITableViewRowAnimationTop)135px高度的单元格时,该动画看起来很奇怪.我试图将self.tableview.cellheight设置为135,并注释掉tableView:cellHeightForIndexPath-Method.动画效果很好.或者我在tableView:cellHeightForIndexPath-Method中将每个cellheight设置为135.

I have a problem with animating deletes and inserts on a UITableView. The Fact ist, that I have different cell heights, some 44.0 some 135.0 now. I have uitableviewstylegrouped with different sections. The first row of each sections is a grouping row. On click I remove all rows of this section except the grouping row. But that animation looks weird, when animating (UITableViewRowAnimationTop) the 135px height cell. I tried to set self.tableview.cellheight to 135 and commented out the tableView:cellHeightForIndexPath-Method. And the Animation works fine. Or I set every cellheight to 135 in tableView:cellHeightForIndexPath-Method.

动画过程似乎检查了各节中第一行的高度,并为随后的所有要制作动画的单元格占用了该单元格的高度.

It looks like the animation process checks the height of the first row in the sections an takes that height of the cell for all following cells to animate.

有人有主意吗?


- (void) showhideGroup:(int)group
{   
    NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
    
    MCGroup *handleGroup = [groups objectAtIndex:group];
    NSMutableArray *groupRows = [visibleGroupData objectForKey:handleGroup.title];
    
    [self.tableView beginUpdates];
    
    if (!handleGroup.hidden) {
        int row = 0;
        for(MobileFieldMapping *field in groupRows)
        {
            if (![field.datatype matchesInsensitive:GROUPING_CELL]) 
            {
                NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:group];
                [indexPaths addObject:path];
            }
            row++;
        }
        
        row = 0;
        for(NSIndexPath *index in indexPaths)
        {
            [groupRows removeObjectAtIndex:index.row-row];
            row++;
        }
        [self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
        handleGroup.hidden=YES;
    }
    else 
    {
        NSMutableArray *allGroupRows = [groupData objectForKey:handleGroup.title];
        
        int row = 0;
        for (MobileFieldMapping *field in allGroupRows) 
        {
            if (![groupRows containsObject:field]) 
            {
                NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:group];
                [indexPaths addObject:path];
                [groupRows insertObject:field atIndex:row];
            }
            row++;
        }
        
        [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
        handleGroup.hidden=NO;
    }
    [self.tableView endUpdates];


    [indexPaths release];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{   
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    
    if ([cell isKindOfClass:[FormCell class]]) 
    {
        return [(FormCell*)cell height];
    }
    
    return 44.0;
}

推荐答案

我遇到了同样的问题. 我的解决方法是使用淡入淡出部分动画:

I had the same problem. My workaround is to use fade section animation:

[tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];

代替元素之一:

[tableView deleteRowsAtIndexPaths:tmpArray withRowAnimation:UITableViewRowAnimationTop];

这看起来更平滑.

这篇关于RowAnimation在不同的高度单元格下看起来很奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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