0

I'm trying to get an expanding transition animation : I have a UICollectionView and when the user select a cell I want this cell to expand to the whole screen. The transition is a Push segue transition

I tried getting the cell location and then animate but I don't think I'm doing it the right way.

I have some class :

  • CollectionViewController : subclass of UICollectionViewController
  • FinalViewController : subclass of UIViewController
  • NavigationControllerDelegate : UINavigationControllerDelegate Protocol implemented
  • Animator : UIViewControllerAnimatedTransitioning protocol implemented

First question : does anyone ever get this effect, have a sample code or know a proper way to achieve this ? This would be really great

Otherwise : How should I get the concerned cell in the Animator class ? I need the frame of the cell, and the subviews. Actually I have a selectedCell property that I set in the prepareForSegue function if the CollectionViewController, but I'm not sure it's the right way

Thanks for your help

Morpheus
  • 1,189
  • 2
  • 11
  • 33

1 Answers1

0

Maybe it's not the way you wanted to achieve it but anyway it could be a good start:

Assuming you have an UIImageView *capturedImView; initialized in your controller. Then when you select a cell, you can try this:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    // Remove the image view (you can do it in a better place)
    [capturedImView removeFromSuperview];

    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];

    // Get the frame of the selected cell in your current view :)
    CGRect frame = [collectionView convertRect:cell.frame toView:self.view];

    // set the capturedImView
    capturedImView.frame = frame;
    UIImage *snapshotImg = [self captureScreenInRect:frame forView:cell];
    capturedImView.image = snapshotImg;
    [self.view addSubview:capturedImView];

    // Play the animation
    [UIView animateWithDuration:3 animations:^{
        // Here we don't care about aspect ratio :s
        capturedImView.frame = self.view.frame;
    }];
}

in which captureScreenInRect:forView: take a snapshot of the view passing in parameter:

- (UIImage *)captureScreenInRect:(CGRect)captureFrame forView:(UIView*)view{
    CALayer *layer;
    layer = view.layer;
    UIGraphicsBeginImageContext(captureFrame.size);
    CGContextClipToRect (UIGraphicsGetCurrentContext(),CGRectMake(0, 0, captureFrame.size.width, captureFrame.size.height));
    [layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *captureImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return captureImage;
}
Y.Bonafons
  • 2,329
  • 13
  • 20
  • Ok, thanks for your help, but I would prefer a more modulable solution (caring about aspect ratio principally :) ) – Morpheus Dec 04 '14 at 17:29
  • I updated my question : http://stackoverflow.com/questions/27302487/magic-move-effect-custom-transition do you have any idea ? – Morpheus Dec 06 '14 at 13:18