diff --git a/DraggableCollectionView/Helpers/LSCollectionViewHelper.m b/DraggableCollectionView/Helpers/LSCollectionViewHelper.m index 77929f6..b55e9e5 100644 --- a/DraggableCollectionView/Helpers/LSCollectionViewHelper.m +++ b/DraggableCollectionView/Helpers/LSCollectionViewHelper.m @@ -59,6 +59,7 @@ - (id)initWithCollectionView:(UICollectionView *)collectionView initWithTarget:self action:@selector(handleLongPressGesture:)]; [_collectionView addGestureRecognizer:_longPressGestureRecognizer]; + _longPressGestureRecognizer.delegate = self; _panPressGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)]; @@ -131,6 +132,8 @@ - (void)setupScrollTimerInDirection:(_ScrollingDirection)direction { } } +#pragma mark - gesture delegate + - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { if([gestureRecognizer isEqual:_panPressGestureRecognizer]) { @@ -152,6 +155,14 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogni return NO; } +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ + CGPoint touchPoint = [touch locationInView:_collectionView]; + if (![_collectionView indexPathForItemAtPoint:touchPoint]){ + return NO; + } + return YES; +} + - (NSIndexPath *)indexPathForItemClosestToPoint:(CGPoint)point { NSArray *layoutAttrsInRect;