I have a normal UITableView
in my UIViewController
, constrained to fullscreen. This tableView has a custom interactive tableHeaderView
. The tableHeaderView is dynamic in size, and expands on its own.
The headerView has a textField, and will change its own size depending on wether the textField has focus or not.
The problem is that the cells at the bottom of the screen aren't always animating correctly when changing the size of the tableHeaderView.
I am calling tableView.beginUpdates()
and tableView.endUpdates()
after layoutIfNeeded()
inside my animation-block. This has to be done, or the cells won't follow the dynamic size at all.
I've made this gif. Look specifically at the bottom cells during the animation. I have slowed down the animation considerably, so it's easy to see the problem.
Speculation: It seems to me like the tableView calls for cellForRow:indexPath:
as soon as the animation starts, and somehow finds out what state the entire tableView will be in after the animation, and removing the unnecessary cells, even though the animation has not yet completed.
The same way, when collapsing the header: the bottommost cells are not animated in the same way as the already loaded cells. They are animated in with a different animation..
Why is this happening? Is this preventable?
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
//Do stuff
}