Is it possible to animate each item individually in a UICollectionView
when I transition to a child View Controller? I have a UICollectionViewController
and when an item is selected I want all items surrounding that item to bounce away from the selected item.
Asked
Active
Viewed 610 times
0

Jeswin
- 238
- 1
- 3
- 16
1 Answers
0
What you describe sounds like a layoutTransition in your UICollectionView. My suggestion would be to create a new layout by subclassing UICollectionViewLayout
and override
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
There you can modify the frames of your items to create the effect you are looking for. In particular, you could keep track of the indexPath that was selected and remain that item unaffected. For the rest you could do something like this:
CGRect selectedItemFrame = [[super layoutAttributesForItemAtIndexPath:self.selectedIndexPath] frame];
CGFloat xOffset = attributes.frame.origin.x <= selectedItemFrame.origin.x ? -400.0 : 400.0;
CGFloat yOffset = attributes.frame.origin.y <= selectedItemFrame.origin.y ? -600.0 : 600.0;
CGRect newFrame = CGRectOffset(attributes.frame, xOffset, yOffset);
attributes.frame = newFrame;
Then, just trigger the transition from one layout to the other.

jjramos
- 1,874
- 14
- 22