【发布时间】:2013-03-21 00:24:33
【问题描述】:
所以我有一个UICollectionView,我希望用户能够张开或伸入以展开和折叠集合单元格。我用this tutorial to perform the expanding and collapsing bit。哪个有效。然后我将下面的代码添加到我的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;
}
}
}
但只有捏出的代码有效。我已经搜索了有关如何正确执行此操作但没有运气的教程或代码。
扩展集合如下所示:
【问题讨论】:
-
听起来您正在使用“巧合的编程”来编写代码。这是一个非常糟糕的做法。您需要了解您的代码是如何工作的,而不是随意更改代码并认为它可以“修复错误”。 "0
-
哈哈谢谢@HaiFengKao!实用编程。我之前想通了,但我没有更新帖子。无论如何,谢谢。
标签: ios ipad uicollectionview uipinchgesturerecognizer