[英]How to Back when CollectionView Image was Zoom
在這里我放大了Collectionview單元格圖像,當它被選中時,但是現在我想在圖像內部進行修飾時再返回到Collection視圖。
這是我的代碼
-(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。
您沒有使用標准方法縮放collectionView:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
// [self.collectionView.collectionViewLayout invalidateLayout];
在您的情況下,您將以全屏方式創建UIImageView
並具有與單元格相同的內容,並將此UIImageView
作為subview
添加以覆蓋所有內容。 因此,如果將zoomImage.alpha
動畫設置為0
並取消隱藏collectionview,則將獲得所需的內容。 完成后,請不要忘記刪除removeFromSuperview
zoomImage。
您可以添加輕擊手勢識別器,甚至可以添加覆蓋與縮放圖像相同區域的透明按鈕。 正如#kabarga所說的,不要忘記刪除removeFromSuperview來擺脫您的imageView。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.