在这里我缩放了Collectionview Cell Image当它被选中但是现在我想在触摸内部图像时使其查看然后返回到集合视图如何可能请给我解决方案
我的代码在这里
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionCenteredHorizontally];
[self zoomToSelectedImage:indexPath];
}
-(void)zoomToSelectedImage:(NSIndexPath *)indexPath
{
NSDictionary *dict = [self.imagesa objectAtIndex:indexPath.item];
NSString *img=[dict valueForKey:@"link"];
UIImageView *zoomImage = [[UIImageView alloc] init];
[zoomImage sd_setImageWithURL:[NSURL URLWithString:img]];
zoomImage.contentMode = UIViewContentModeScaleAspectFit;
zoomImage.backgroundColor=[UIColor grayColor];
zoomImage.userInteractionEnabled=YES;
UIPinchGestureRecognizer *pinchgesture=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchGestureDetected:)];
[pinchgesture setDelegate:self];
[zoomImage addGestureRecognizer:pinchgesture];
UIPanGestureRecognizer *pangausture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGestureDetected:)];
[pangausture setDelegate:self];
[zoomImage addGestureRecognizer:pangausture];
self.imagecollection.hidden=TRUE;
CGRect zoomFrameTo = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
UICollectionViewCell *cellToZoom =(UICollectionViewCell *)[self.imagecollection cellForItemAtIndexPath:indexPath];
CGRect zoomFrameFrom = cellToZoom.frame;
[self.view addSubview:zoomImage];
zoomImage.frame = zoomFrameFrom;
zoomImage.alpha = 0.2;
[UIView animateWithDuration:0.01 animations:
^{
zoomImage.frame = zoomFrameTo;
zoomImage.alpha = 1;
} completion:nil];
}
Imagecollection是我的Collectionview .
2 回答
您不是使用标准方法缩放collectionView:
在您的情况下,您使用与单元格中相同的内容全屏创建
UIImageView
,并将此UIImageView
添加为subview
以涵盖所有内容 . 因此,如果您将zoomImage.alpha
设置为0
并取消隐藏集合视图,则可以获得所需内容 . 完成时不要忘记removeFromSuperview
zoomImage .您可以添加轻击手势识别器,甚至是覆盖与缩放图像相同区域的透明按钮 . 正如#kabarga所说,不要忘记删除FreeSuperview以摆脱你的imageView .