Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement this cell animation with UICollectionView

I'm trying to make this animation

For the list, I think I can use UICollectionView, but the animation part seem to be tricky.

Any idea on this?

like image 292
jAckOdE Avatar asked Oct 03 '22 03:10

jAckOdE


2 Answers

If you mean the springing animation part, that is not very tricky - Apple has a demo of exactly that behavior in same code for UIDynamics (iOS7+ only).

There is another example here that looks very close to what you are after:

http://www.objc.io/issue-5/collection-views-and-uidynamics.html

Look in the middle for an animated example. It even uses collection views.

like image 135
Kendall Helmstetter Gelner Avatar answered Oct 10 '22 04:10

Kendall Helmstetter Gelner


As @Kendall said, you really need to try UIDynamics.

For a quick workaround, I just tried below code. It works somewhat good and related to your code. I don't know about performance. So It may create a performance lack in your project.

It is just an idea. If it is not working for you, leave it as it is.

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCollectionViewCell" forIndexPath:indexPath];

    [UIView animateWithDuration:0.2 animations:^{
        cell.transform = CGAffineTransformMakeTranslation(0.0, -50);
    }];
    [self delayBy:0.5 code:^{ // call block of code after time interval
        [UIView animateWithDuration:0.3 animations:^{
            cell.transform = CGAffineTransformIdentity;
        }];
    }];
    return cell;
}
like image 33
Dinesh Raja Avatar answered Oct 10 '22 06:10

Dinesh Raja