How to animate the height change of an section header in UITableView?

前端 未结 4 914
再見小時候
再見小時候 2020-12-13 20:48

I\'ve implemented this method to return the section header height. However, when the height for the section changes, it happens immediately without animation.

4条回答
  •  攒了一身酷
    2020-12-13 21:20

    I haven't tested this, but sometimes I get unwanted animations when my UITableViewCells change height. The cause of this is that I draw my own cells, and I use CALayers to do so. In the cell's (void)layoutSubviews I would change the size of my CALayer to be the size of the frame for the cell

    myLayer.frame = self.bounds;
    

    When the frame/bounds property of a CALayer changes, it is animated. So in theory, I would say that you could use the method tableView:viewForHeaderInSection: which would allow you to draw your own section header. You could just return a UIView that implements (void)layoutSubviews and then in that method do

    self.layer.frame = self.bounds;
    

    Just an idea.

提交回复
热议问题