Imran Rony
Imran Rony

Reputation: 61

Animating the expansion of a UICollectionViewCell's content upon selection

How to animate the expansion of a UICollectionViewCell's content upon selection?

Currently I'm using transition animation on my didSelectItemAtIndexPath for animating a view Which isn’t working smoothly like AppStore card animation.

Here is my current code...

AnimateStaticImageViewController *animateImageVC = [[AnimateStaticImageViewController alloc] init];
animateImageVC.modalPresentationStyle = UIModalPresentationFullScreen;
animateImageVC.modelImage = [UIImage imageNamed:text];

[UIView animateWithDuration:0.7 animations:^{
        animateImageVC.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.3);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.7 animations:^{
            animateImageVC.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.7 animations:^{
                animateImageVC.view.transform = CGAffineTransformIdentity;
            }];
        }];
    }];
    
[self presentViewController:animateImageVC animated:NO completion:nil];

Upvotes: 0

Views: 160

Answers (1)

Imran Rony
Imran Rony

Reputation: 61

So, I was trying a modal transition animation in my app's home page staticImageCollectionView immediately after clicking the image. The core animation & transform mechanism didn't work for me as I need something like AppStore's card animation. Using this library worked after some hassle! Following this...

  1. Setting the library with following steps.

  2. Calling the transitioningDelegate of the animationViewController on didSelectItemAtIndexPath (or prepareForSegue if working with segue-navigation controller).

  3. Calling it within a completion block to ignore flickering & delay issue in view presentation.

AnimatedStaticImageViewController *animateImageVC = [[AnimatedStaticImageViewController alloc] init];
animateImageVC.modalPresentationStyle = UIModalPresentationFullScreen;
animateImageVC.modelImage = [UIImage imageNamed:text];
    
[UIView animateWithDuration:0.2
                     animations:^{
        animateImageVC.transitioningDelegate = self;
    } completion:^(BOOL finished) {
        [self.view removeFromSuperview];
        [self presentViewController:animateImageVC animated:YES completion:nil];
}];
  1. Be careful when setting imageView which is the main presentation of the animation.

  2. Make sure you declaring the delegate 'RMPZoomTransitionAnimating' & 'RMPZoomTransitionDelegate' methods on both fromViewController and toViewController.

Upvotes: 1

Related Questions