How to zoom a UIScrollView inside of a UICollectionViewCell?

后端 未结 7 982
天涯浪人
天涯浪人 2020-12-04 20:10

I\'m trying to add a UIScrollView inside of a UICollectionViewCell. The idea is that you can use pinch to zoom the UIScrollView (and w

7条回答
  •  独厮守ぢ
    2020-12-04 20:25

    Please add scrollview in your cell and your current cell image view add in scrollview. then use below code:

    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        ImageContext *context = [self.images objectAtIndex:indexPath.row];
        ImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"imageCell" forIndexPath:indexPath];
        cell.cellScrollView.autoresizesSubviews = YES;
        cell.cellScrollView.multipleTouchEnabled =YES;
        cell.cellScrollView.maximumZoomScale = 4.0;
        cell.cellScrollView.minimumZoomScale = 1.0;
        cell.cellScrollView.clipsToBounds = YES;
        cell.cellScrollView.delegate = self;
        cell.cellScrollView.zoomScale = 1.0;
    
        [cell.imageView setImage:[UIImage imageNamed:context.thumbImageUrl]];
    
    return cell;
    }
     -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
     {   NSLog(@"%i",scrollView.subviews.count);
      for (UIView *v in scrollView.subviews) {
        if ([v isKindOfClass:[UIImageView class]]) {
            return v;
          }
      }
    

    }

提交回复
热议问题