尝试将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
完全警告,我没有编译或测试过这种方法,但我认为它应该可以工作。:)