1。相关方法
- (void)invalidateLayout // 刷新布局
e.g.
- (void) handlePinches:(UIPinchGestureRecognizer *)paramSender{
CGSize DefaultLayoutItemSize = CGSizeMake(80.0f, 120.0f); //这是原先设置的默认的尺寸大小,这里每次缩放都是以默认尺寸为基数
UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
layout.itemSize = CGSizeMake(DefaultLayoutItemSize.width * paramSender.scale, DefaultLayoutItemSize.height * paramSender.scale);
[layout invalidateLayout]; //废弃旧布局,更新新布局
}
- (void) viewDidLoad{
[super viewDidLoad];
self.collectionView.backgroundColor = [UIColor whiteColor];
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinches:)];
for (UIGestureRecognizer *recognizer in self.collectionView.gestureRecognizers){
if ([recognizer isKindOfClass:[pinch class]]){
[recognizer requireGestureRecognizerToFail:pinch]; //此处使用是为了确保各缩放手势保持独立,不会混淆
// [aGesture requireGestureRecognizerToFail: bTapGesture]; //b手势无效后,才能承认a手势(如双击无效后才承认单击等,确保不混淆手势)
}
}
[self.collectionView addGestureRecognizer:pinch];
}