Can you animate a height change on a UITableViewCell when selected?

前端 未结 21 1052
天涯浪人
天涯浪人 2020-11-22 04:41

I\'m using a UITableView in my iPhone app, and I have a list of people that belong to a group. I would like it so that when the user clicks on a particular pers

21条回答
  •  别那么骄傲
    2020-11-22 04:58

    I just resolved this problem with a little hack:

    static int s_CellHeight = 30;
    static int s_CellHeightEditing = 60;
    
    - (void)onTimer {
        cellHeight++;
        [tableView reloadData];
        if (cellHeight < s_CellHeightEditing)
            heightAnimationTimer = [[NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(onTimer) userInfo:nil repeats:NO] retain];
    }
    
    - (CGFloat)tableView:(UITableView *)_tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
            if (isInEdit) {
                return cellHeight;
            }
            cellHeight = s_CellHeight;
            return s_CellHeight;
    }
    

    When I need to expand the cell height I set isInEdit = YES and call the method [self onTimer] and it animates the cell growth until it reach the s_CellHeightEditing value :-)

提交回复
热议问题