Ios 长时间按住并拖动UICollectionView多选

Ios 长时间按住并拖动UICollectionView多选,ios,objective-c,uicollectionview,uigesturerecognizer,uicollectionviewcell,Ios,Objective C,Uicollectionview,Uigesturerecognizer,Uicollectionviewcell,我试图通过长按一个单元格,然后拖动到其他单元格来选择UICollectionView中的多个单元格 我已经成功地使用平移手势识别器来定位单元格并调用方法来选择它: - (void) didPanToSelectCells:(UIPanGestureRecognizer*) panGesture{ if (!_collectionView.selectionMode){ [self.collectionView setScrollEnabled:YES];

我试图通过长按一个单元格,然后拖动到其他单元格来选择UICollectionView中的多个单元格

我已经成功地使用平移手势识别器来定位单元格并调用方法来选择它:

- (void) didPanToSelectCells:(UIPanGestureRecognizer*) panGesture{
    if (!_collectionView.selectionMode){
        [self.collectionView setScrollEnabled:YES];
        return;
    }else{
        if (panGesture.state == UIGestureRecognizerStateBegan){
            [self.collectionView setUserInteractionEnabled:NO];
            [self.collectionView setScrollEnabled:NO];

        }else if (panGesture.state == UIGestureRecognizerStateChanged){
            CGPoint location = [panGesture locationInView:self.collectionView];

            NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:location];

            if (![_collectionView.selectedIndexes containsObject:@(indexPath.row)]){
                [self.collectionView selectCell:[self.collectionView cellForItemAtIndexPath:indexPath] atIndexPath:indexPath selected:YES];
            }
        }else if (panGesture.state == UIGestureRecognizerStateEnded){
            [self.collectionView setScrollEnabled:YES];
            [self.collectionView setUserInteractionEnabled:YES];
        }
    }
}
然而,当我打电话时:

[self.collectionView selectCell:[self.collectionView cellForItemAtIndexPath:indexPath] atIndexPath:indexPath selected:YES];
什么也没发生! 我可以用另一种方法调用它,它工作得很好,但是当从手势识别器调用时,它什么也不做

我还添加了以下手势识别器代理方法,但没有效果:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
以及:

有人知道如何正确地执行此操作吗?


谢谢大家!

你有没有找到解决办法?
[gestureRecognizer setCancelsTouchesInView:NO];