Usually you get unwanted animations on UITableViewCells when animating the height of the UITableView. The new cells that get reused come in and have weird unwanted animations on the subviews that get laid out. This is usually visible when the table expands.
The animations usually look like the objects pop in from a corner since it animates the width and height of the subviews for some reason from 0 to the size they're supposed to be.
This can sort of be solved by overriding in the cell's layoutSubviews method.
- (void)layoutSubviews
{
[UIView performWithoutAnimation:^{
[super layoutSubviews];
}];
}
But this still doesn't prevent the contained subviews from doing unwanted animations. It also doesn't prevent unwanted animations when you add things to contentView of a cell. You basically have to override the layoutSubviews methods of every single subview you have if it too has subviews.
This isn't always possible, like in the case of contentView. I can't override the contentView class and tell it to lay out its subviews without animations. This is also a very cumbersome fix since I need to add this to every single UIView object that I am able to override.
I still haven't found the answer that fixes this once and for all. How to just animate a constraint on something but prevent strange unwanted animations on its subviews.
I encountered a similar problem in a UICollectionView and was able to fix it in its delegate:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
// setup your cell
// ...
[UIView performWithoutAnimation:^{
[cell layoutIfNeeded];
}];
return cell;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With