如何在选中时缩放UICollectionviewCell图像?

时间:2014-10-28 08:51:39

标签: ios uicollectionview

我创建了一个应用程序,它使用CustumCell来控制UICollectionview,并且当我选择任何图像时,我想要制作每个Cell包含的图像,然后放大视图和缩放视图触摸 然后将collectionview显示为URBMediaFocusViewController Libraray

图书馆的链接在这里URBMediaFocusViewController

我知道它被多次询问但是请给我解决方案。

1 个答案:

答案 0 :(得分:1)

它不是很优雅,但我就是这样做的。基本上获取源UICollectionView Cell的框架位置和大小,您希望它出现的框架和位置(在本例中我填充视图),然后在两种尺寸之间设置动画。希望这会有所帮助。

- (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];