Objective C - UICollectionView - 双击全屏缩放

时间:2017-04-08 19:28:09

标签: ios objective-c uicollectionview zoom

我需要一些关于缩放整个collectionView的帮助。我在互联网上搜索了很多,但大多数答案都与UIScrollView和Pinch手势有关。我正在添加一个捏手势,这是无效的布局collectionView和返回规模。我需要一些像这样的解决方案,双击缩放,这给我比例,所以我可以在运行时计算项目大小。

有什么建议吗?

修改

- (void)pinch:(UIPinchGestureRecognizer *)gesture {

   static CGFloat scaleStart;
   static CGPoint p;

   if (gesture.state == UIGestureRecognizerStateBegan)
   {
   scaleStart = self.scale;
   p = self.collectionView.contentOffset;
   }
   else if (gesture.state == UIGestureRecognizerStateChanged)
   {
   CGFloat tempScale = scaleStart * gesture.scale;
   if (tempScale < MINIMUM_SCALE)
   {
   self.scale = MINIMUM_SCALE;
   }
   else if (tempScale > MAXIMUM_SCALE)
   {
   self.scale = MAXIMUM_SCALE;
   }
   else
   {
   self.scale = tempScale ;
   }

   dispatch_async(dispatch_get_main_queue(), ^{

   [self.collectionView.collectionViewLayout invalidateLayout];

   //self.collectionView.contentOffset = CGPointMake(0, p.y * gesture.scale);
   });
   }


-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat collectionCellWidth =  ([[UIScreen mainScreen] bounds].size.width);

    return CGSizeMake(collectionCellWidth * self.scale, collectionView.frame.size.height * self.scale );
}

0 个答案:

没有答案