我正在使用UIPanGestureRecognizer
在contentView
上平移我的UICollectionViewCell
。我正在实施双方的滑动手势。我正在使用平底锅,因为我希望能够将视图反弹(动画)回原点。
UICollectionView
是包含行的单个部分,其中每行是单个项目单元格(思考表格)。
问题是当我向下滚动UICollectionView
时,我无意中导致我的细胞移动,因为发生的拖动翻译非常少。我已经尝试实现UIScrollViewDelegate
方法来尝试防止细胞在滚动期间无意中移动,但即使“触摸细胞”边缘情况仍然会引发细胞稍微平移。这感觉不对,因为当你滚动并且你的拇指触摸细胞时,你会看到许多细胞泛着。
滚动时如何防止这种敏感度有什么好主意吗?例如,当您滚动时,默认Apple Mail.app似乎没有此问题;似乎存在某种阻力。
一些想法:
UIScrollView
而不是平移手势识别器,但我还需要以某种方式支持在另一侧滑动。任何想法都会受到赞赏。
答案 0 :(得分:0)
尝试设置UICollectionView
的平移手势,以使UICollectionViewCell
无效。使用此方法:
// create a relationship with another gesture recognizer that will prevent this gesture's actions from being called until otherGestureRecognizer transitions to UIGestureRecognizerStateFailed
// if otherGestureRecognizer transitions to UIGestureRecognizerStateRecognized or UIGestureRecognizerStateBegan then this recognizer will instead transition to UIGestureRecognizerStateFailed
// example usage: a single tap may require a double tap to fail
- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer;
可能通过在创建时传递的单元格上添加属性?
@interface YourCollectionViewCell : UICollectionViewCell
@property (weak, nonatomic) UIGestureRecognizer *blockingGestureRecognizer;
@property (strong, nonatomic) UIGestureRecognizer *internalSwipeGestureRecognizer;
@end
@implementation YourCollectionViewCell
- (void)setBlockingGestureRecognizer:(UIGestureRecognizer *)blockingGestureRecognizer {
_blockingGestureRecognizer = blockingGestureRecognizer;
[self.internalSwipeGestureRecognizer requireGestureRecognizerToFail:blockingGestureRecognizer];
}
@end
@interface YourViewController : UIViewController
#pragma mark - UICollectionViewDataSource
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:YourCollectionViewCell.identifier forIndexPath:indexPath];
cell.blockingGestureRecognizer = collectionView.panGestureRecognizer;
return cell;
}
@end
完全警告,我没有编译或测试这种方法,但我认为它应该有效。 :)