Absolutely! But you cannot do it right using the UIView animation UIView . You need to delve into Core Animation.
In the collection view, animations are added to CALayer that support each UICollectionViewCell . But if you implement your own layout (or a subclass of an existing one), you can make all the necessary changes for these animations in the finalizeCollectionViewUpdates method.
From the documentation of the UICollectionViewLayout class:
The collection view calls this method as the last step before the previous one to animate any changes.
Here is an example of how to replace the default position animation with your own:
- (void)finalizeCollectionViewUpdates { for (UICollectionViewCell *cell in [self.collectionView visibleCells]) { CAAnimation *positionAnimation = [cell.layer animationForKey:@"position"]; if (positionAnimation) { [cell.layer removeAnimationForKey:@"position"]; CALayer *presentationLayer = cell.layer.presentationLayer; CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; [animation setFromValue:[NSValue valueWithCGPoint:presentationLayer.position]]; [animation setToValue:[NSValue valueWithCGPoint:cell.layer.position]]; [animation setDuration:0.4]; [cell.layer addAnimation:animation forKey:@"position"]; } } }
Look at the animation-related methods on CALayer to find out how you can delve into what kind of animations are currently running on your layer.
Using this approach, you can even get creative and add overshoot / bounce effects using CAKeyframeAnimation or anything else you can think of. You can also do things like selectively turn off some animations (like size) and save others (like position).
source share