Search code examples
ioscocoa-touchuitableviewanimationcore-animation

Animating a UITableView's header and footer


I'm struggling to animate the removal of a tableview's header/footer content with animation. I believe I can call either removeFromSuperview on the header contents itself, or just assign the header to nil, but I don't know how to animate this. A simple animation block doesn't do anything - how do I fade a view (a label in this case) in/out?


Solution

  • I wrote an example of how to remove the header view altogether using animation blocks.

    [UIView beginAnimations:nil context:NULL];
    [self.tableView setTableHeaderView:nil];
    [UIView commitAnimations];
    

    This assumes the animation is being called inside of your UITableViewController class.

    Simply removing the header view from the superview doesn't work because the table view doesn't know to resize itself to fill up what used to be the header view. The setting of the header view causes the table view to animatedly refresh itself.

    If this doesn't work, check your assignment(s) of the tableView instance.