Following on from a previous SO question which I asked, I am attempting to animate the change in height of a UICollectionView
(which is yellowBox
in the example). This change in height is being triggered by modifying the auto layout constraints on the collection view with the following code:
- (IBAction)expandYellowBox:(id)sender {
[UIView animateWithDuration:0.5
animations:^{
self.yellowBoxHeightConstraint.constant += 50;
[self.view layoutIfNeeded];
}];
}
However, when I call [self.view layoutIfNeeded]
this results in the collection view being reloaded, so it flashes visibly to the user. However, I don't want the collection view to reload but instead just to animate its height change. Is there any way to either avoid -layoutIfNeeded
reloading the collection view, or an alternative way to animate the constraint height change which doesn't call a method which has the side-effect of reloading the collection view?
In case anyone else encounters this problem, it was because I was actually calling
[self.collectionView reloadData]
a few lines above the animation block (and didn't notice!). It seems that calling-reloadData
and-layoutIfNeeded
causes the collection view to flash. Removing the call to-reloadData
resolves the problem.