0

I have an app with 3 sections, each with a footer. I've established this through viewForFooterInSection, and set the height for each using heightForFooterInSection.

These footers are not fixed size, as they change height based on certain things. When the height changes, it's a quite choppy animation. Rather than showing the height change, it just jumps from the old height to the new height.

if (condition == YES) {
    return 45;
}

else {
    return 70;
}

Is there a way to animate this height change to provide a more smooth experience? Thanks!

mhbdr
  • 753
  • 2
  • 10
  • 26
  • Have you tried using the solution similar to animated cell height change from http://stackoverflow.com/questions/460014/can-you-animate-a-height-change-on-a-uitableviewcell-when-selected ? – Alexander N. Jan 19 '13 at 19:18
  • Hah, I just put that in an answer below. – jrturton Jan 19 '13 at 19:23

2 Answers2

0

Create a custom footer view and keep a local var of it...

- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return self.footerView;
}

Then you should be able to call

[self.footerView updateHeightForCondition:YES]; //or NO

as needed.

Which would be something like ...

[UIView animateWithDuration:0.5f animations:^{
    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, condition ? 45 : 70);
}];

If you override viewForFooter you do not need to override heightForFooterInSection or titleForFooterInSection anymore.

miex
  • 64
  • 6
0

This works for animating changes to cell height, I see no reason why it wouldn't also work for header and footer height. I'm not able to test this myself at the moment so apologies if it doesn't work - let me know and I'll delete it.

Make whatever changes to your model or controller properties (such that the next time heightForFooter.. is called, the new value will be returned). Then, simply call:

[self.tableView beginUpdates];
[self.tableView endUpdates];

It seems unusual to call these two methods with nothing between, but this causes the table to requery its delegate and datasource to obtain a new size, and animate to that new size. Usually you'd have added or removed rows, but changing sizes is also covered.

jrturton
  • 118,105
  • 32
  • 252
  • 268