I have a normal UITableView in my UIViewController limited to full screen. This tableView has a custom interactive tableHeaderView . TableHeaderView is dynamic in size and extends by itself. The header has a text filter and will change its own size depending on whether the textField object has focus or not.
The problem is that the cells at the bottom of the screen are not always animated correctly when resizing the HeaderView table. I call tableView.beginUpdates() and tableView.endUpdates() after layoutIfNeeded() inside my animation block. This must be done or the cells will not follow the dynamic size at all.
I made this gif. Look specifically at the bottom cells during the animation. I significantly slowed down the animation, so it's easy to see the problem.

Speculation: It seems to me that the tableView calls cellForRow:indexPath: as soon as the animation starts, and somehow finds out what state the whole tableView will be after the animation, and deleting unnecessary cells, even if the animation is not completed yet. Similarly, when smoothing the header: the lowest cells do not animate in the same way as already loaded cells. They are animated with a different animation.
Why is this happening? Can this be prevented?
Edit: Animation code
self.navigationController?.setNavigationBarHidden(isEditing, animated: true) var frame = tableHeaderView.frame frame.size.height = tableHeaderView.headerHeight(forEditing: isEditing) UIView.animate(withDuration: 0.3, animations: { if isEditing{ let point = CGPoint(x: 0, y: -self.topLayoutGuide.length) self.tableView.setContentOffset(point, animated: false) } tableHeaderView.frame = frame tableHeaderView.layoutIfNeeded() self.view.layoutIfNeeded() self.tableView.beginUpdates() self.tableView.endUpdates() }) { [weak self](completed:Bool) in
source share