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

前端 未结 21 1041
天涯浪人
天涯浪人 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 05:09

    I found a REALLY SIMPLE solution to this as a side-effect to a UITableView I was working on.....

    Store the cell height in a variable that reports the original height normally via the tableView: heightForRowAtIndexPath:, then when you want to animate a height change, simply change the value of the variable and call this...

    [tableView beginUpdates];
    [tableView endUpdates];
    

    You will find it doesn't do a full reload but is enough for the UITableView to know it has to redraw the cells, grabbing the new height value for the cell.... and guess what? It ANIMATES the change for you. Sweet.

    I have a more detailed explanation and full code samples on my blog... Animate UITableView Cell Height Change

提交回复
热议问题