I'm trying to add dynamic, animated movement to the cells in my UICollectionView / custom layout.
Basically... when a user taps cell A, it moves to the center, pushing all the other nearby cells (radially) out of its way, and then those cells crowd around it, filling up the space.
Now, when the user taps it again, I want the animation to invert.
And if the user scrolls, I want the animation to fluidly, continuously, and incrementally proceed or rewind, until some threshold point where it goes all the way in that direction.
Brainstorm
Recalculating the relevant cells' frames upon every signal from the UIScrollView, then continuously animating the change from the old layout to the new one with setCollectionViewLayout: animated:
crossed my mind... but not only does it feel a horribly stupid way to do it... it won't work when new signals come mid-animation.
Can I not just grab the frames of the visible cells and animate their frame changes, like with any regular view? Using transitionWithView:duration:options:animations:completion:
and UIViewAnimationOptionBeginFromCurrentState
to keep the motion continuous and updatable?
Any other ideas?
EDIT-- Current Tentative Solution
At the moment, I'm going to try...
1) Reach into the collection view's visible cells, to just grab the relevant cells and animate the frame changes when necessary.
2) I'm going to use this CALayer trick Core animation progress callback, so that I can get continuous position update signals for the driving cell, to drive the animations of the cells it needs to push away when they come into contact.
3) I'll use shouldInvalidateLayoutForBoundsChange:
with transitionWithView:duration:options:animations:completion:
and UIViewAnimationOptionBeginFromCurrentState
to implement the fluid, on demand, play / rewind function
(quick visual example)