缩放整个UICollectionView

我有一个iPad应用程序,我使用的是一个UICollectionView,每个UICollectionViewCell只包含一个UIImage。 目前我每页显示9 UIImages(3行* 3列),我有几页。

我想使用捏手势放大整个UICollectionView来增加/减less每页显示的行/列的数量,最好的是在捏手势期间有美丽的缩放animation!

目前,我在我的UICollectionView中添加了一个捏手势。 我捕捉捏手势事件来计算使用比例因子的行/列的数量,如果它已经改变,那么我更新完整的UICollectionView使用:

[_theCollectionView performBatchUpdates:^{ [_theCollectionView deleteSections:[NSIndexSet indexSetWithIndex:0]]; [_theCollectionView insertSections:[NSIndexSet indexSetWithIndex:0]]; } completion:nil]; 

它可以工作,但在转换过程中我没有stream畅的animation。

任何想法? UICollectionViewinheritance自UIScrollView,是否有可能重新使用UIScrollView捏手势function来达到我的目标?

我假设你正在使用默认的UICollectionViewDelegateFlowLayout,对不对? 然后确保你相应地响应代表方法,当捏合手势发生时,简单地使布局无效。

例如,如果我想调整每个项目的大小,而捏:

 @interface ViewController () <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout> @property (nonatomic,assign) CGFloat scale; @property (nonatomic,weak) IBOutlet UICollectionView *collectionView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.scale = 1.0; [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"]; UIPinchGestureRecognizer *gesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(didReceivePinchGesture:)]; [self.collectionView addGestureRecognizer:gesture]; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(50*self.scale, 50*self.scale); } - (void)didReceivePinchGesture:(UIPinchGestureRecognizer*)gesture { static CGFloat scaleStart; if (gesture.state == UIGestureRecognizerStateBegan) { scaleStart = self.scale; } else if (gesture.state == UIGestureRecognizerStateChanged) { self.scale = scaleStart * gesture.scale; [self.collectionView.collectionViewLayout invalidateLayout]; } } 

属性self.scale只是为了显示,你可以将这个相同的概念应用到任何其他属性,这不需要beginUpdates / endUpdates,因为用户本人正在进行的规模的时间。

这是一个正在运行的项目 ,如果你想看到它的行动。

对不起我的2美分的问题,我已经find了解决scheme,非常简单。

在我的PinchGesturecallback中,我刚刚完成了以下操作:

 void (^animateChangeWidth)() = ^() { _theFlowLayout.itemSize = cellSize; }; [UIView transitionWithView:self.theCollectionView duration:0.1f options:UIViewAnimationOptionCurveLinear animations:animateChangeWidth completion:nil]; 

我的UICollectionView所有单元格都成功更改,并有一个很好的transition