In tableView:willDisplayCell:forRowAtIndexPath:
delegate method, you can retrieve current displaying (i.e. old) cell with cellForRowAtIndexPath:
method.
Using this, you can do that with reloadRowsAtIndexPaths:withRowAnimation:
method.
What you have to do is:
- match new cell's label position with old cell
- animate both cell's label to new position
like:
- (void)tableView:(UITableView *)tableView willDisplayCell:(BaseCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
BaseCell *oldCell = (BaseCell *)[self.tableView cellForRowAtIndexPath:indexPath];
if(oldCell != nil && oldCell != cell) {
CGRect oldFrame = oldCell.titleLabel.frame;
CGRect newFrame = cell.titleLabel.frame;
cell.titleLabel.frame = (CGRect){oldFrame.origin, newFrame.size};
[UIView animateWithDuration:0.25 animations:^{
oldCell.titleLabel.frame = (CGRect){newFrame.origin, oldFrame.size};
cell.titleLabel.frame = (CGRect){newFrame.origin, newFrame.size};
} completion:^(BOOL finished) {
// reset oldCell's titleLabel position for reuse
oldCell.titleLabel.frame = oldFrame;
}];
}
}
A few things you have to care about:
- Do not use autolayout for cell nib. that will make things too complicated.
- Be sure to reset label's position for reuse.
- Use
UITableViewRowAnimationFade
for reloadRowsAtIndexPaths:withRowAnimation:
.