Ashish Gabani
Ashish Gabani

Reputation: 443

How to Zoom CollectionviewCell Image when it was Selected?

i make an application that conatin UICollectionview with CustumCell and each Cell Contain images i want to make when any image selected then it was zoom in view and when zoom view touch then collectionview was Shown like as a URBMediaFocusViewController Libraray

link of library is here URBMediaFocusViewController

i know it was asked many times but please give me solution.

Upvotes: 1

Views: 1840

Answers (1)

Gismay
Gismay

Reputation: 814

It's not very elegant, but this is how I do it. Basically get the frame location and size of your source UICollectionView Cell, the frame and location of where you want it to appear (in this case I fill the view), then animate between the two sizes. Hope this helps.

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

{

    [collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionCenteredHorizontally];

   [self zoomToSelectedImage:indexPath];

}


-(void)zoomToSelectedImage:(NSIndexPath *)indexPath

{

    UIImageView *zoomImage = [[UIImageView alloc] initWithImage:[self.myPictures objectAtIndex:indexPath.row]];

zoomImage.contentMode = UIViewContentModeScaleAspectFit;

CGRect zoomFrameTo = CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height);

UICollectionView *cv = (UICollectionView *)[self.view viewWithTag:66]; // Change to whatever the tag value of your collectionView is 

cv.hidden = TRUE;

UICollectionViewCell *cellToZoom =(UICollectionViewCell *)[cv cellForItemAtIndexPath:indexPath];

CGRect zoomFrameFrom = cellToZoom.frame;

[self.view addSubview:zoomImage];

zoomImage.frame = zoomFrameFrom;

zoomImage.alpha = 0.2;

[UIView animateWithDuration:0.2 animations:

^{

     zoomImage.frame = zoomFrameTo;

     zoomImage.alpha = 1;

 } completion:nil];

Upvotes: 1

Related Questions