所以我有一个UICollectionView
并且我希望用户能够伸出或收缩来展开和折叠收集单元格。我使用本教程来执行展开和折叠位。哪个有效。然后我将下面的代码添加到我的collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
委托方法中。
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchCollection:)];
[cell addGestureRecognizer:pinchGesture];
然后创建这样的动作pinchCollection:
:
-(void)pinchCollection:(id)sender {
UIPinchGestureRecognizer *gesture = (UIPinchGestureRecognizer*)sender;
if (gesture.state == UIGestureRecognizerStateBegan) {
if (gesture.scale <= -1) { // I also changed this to be gesture.scale < 1 but it didn't work.
// pinch in
[self collapseCollection];
gesture.scale = 1;
}
if (gesture.scale >= 1) { // I changed this to be gesture.scale > 1 but it didn't work either.
// pinch out
[self expandCollection];
gesture.scale = -1;
}
}
}
但只有捏出代码有效。我已经搜索了有关如何正确执行此操作但没有运气的教程或代码。
扩展集合如下所示: