From 55857336e67c931ae5fb5ae10c89f7292c162c69 Mon Sep 17 00:00:00 2001 From: Jose Manuel Silva Vela Date: Sun, 7 Dec 2014 21:35:59 -0500 Subject: [PATCH 1/2] Updated method to use previous implementation. Added additional validation to remove triggering deletion in a very sensitive scenario --- .../LSSwipeToDeleteCollectionViewLayout.m | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/LSSwipeToDeleteCollectionViewLayout/LSSwipeToDeleteCollectionViewLayout.m b/LSSwipeToDeleteCollectionViewLayout/LSSwipeToDeleteCollectionViewLayout.m index c03405d..69ff7e8 100644 --- a/LSSwipeToDeleteCollectionViewLayout/LSSwipeToDeleteCollectionViewLayout.m +++ b/LSSwipeToDeleteCollectionViewLayout/LSSwipeToDeleteCollectionViewLayout.m @@ -249,7 +249,7 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)gesture{ } }; - if (!shouldDelete || gesture.state == UIGestureRecognizerStateFailed || gesture.state == UIGestureRecognizerStateCancelled || [self translationValue] < self.deletionDistanceTresholdValue || [self velocityMagnitude] < self.deletionVelocityTresholdValue || [self velocity] > 0) { + if (!shouldDelete || gesture.state == UIGestureRecognizerStateFailed || gesture.state == UIGestureRecognizerStateCancelled) { [self cancelSwipeToDeleteWithCompletion:completionBlock]; }else{ NSArray *indexPathsToDelete = @[selectedIndexPath]; @@ -287,7 +287,7 @@ -(LSSwipeToDeleteDirection)deletionDirectionWithGestureRecogniser:(UIPanGestureR if (escapeDistance > self.deletionDistanceTresholdValue && [self isTranslationInDeletionDirection:tranlastion]) { direction = [self swipeToDeleteDirectionFromValue:tranlastion]; - }else if (escapeVelocity > self.deletionVelocityTresholdValue && [self isVelocityInDeletionDirection:velocity]){ + }else if (escapeVelocity > self.deletionVelocityTresholdValue && [self isVelocityInDeletionDirection:velocity] && escapeDistance > self.deletionDistanceTresholdValue){ direction = [self swipeToDeleteDirectionFromValue:tranlastion]; } @@ -382,11 +382,6 @@ -(CGFloat)translationValue{ -(CGFloat)velocityMagnitude{ - return fabsf([self velocity]); -} - --(CGFloat)velocity{ - CGPoint velocity = [self.panGestureRecognizer velocityInView:[self.panGestureRecognizer view]]; CGFloat velocityValue = 0.0f; @@ -395,8 +390,8 @@ -(CGFloat)velocity{ }else if (self.scrollDirection == UICollectionViewScrollDirectionHorizontal){ velocityValue = velocity.y; } - return velocityValue; + return fabsf(velocityValue); } -(LSSwipeToDeleteDirection)swipeToDeleteDirectionFromValue:(CGPoint)value{ From b7b6ca9f3b574290570e81ad147a1da6f22ac515 Mon Sep 17 00:00:00 2001 From: Jose Manuel Silva Vela Date: Sun, 7 Dec 2014 21:50:06 -0500 Subject: [PATCH 2/2] Added behavior to prevent deleting under extremely sensitive swipe with high acceleration --- .../LSSwipeToDeleteCollectionViewLayout.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/LSSwipeToDeleteCollectionViewLayout/LSSwipeToDeleteCollectionViewLayout.m b/LSSwipeToDeleteCollectionViewLayout/LSSwipeToDeleteCollectionViewLayout.m index 349ad26..3e0ff0b 100644 --- a/LSSwipeToDeleteCollectionViewLayout/LSSwipeToDeleteCollectionViewLayout.m +++ b/LSSwipeToDeleteCollectionViewLayout/LSSwipeToDeleteCollectionViewLayout.m @@ -224,7 +224,7 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)gesture{ break; } - + case UIGestureRecognizerStateEnded: case UIGestureRecognizerStateCancelled: case UIGestureRecognizerStateFailed: @@ -395,6 +395,11 @@ -(CGFloat)translationValue{ -(CGFloat)velocityMagnitude{ + return fabsf([self velocity]); +} + +-(CGFloat)velocity{ + CGPoint velocity = [self.panGestureRecognizer velocityInView:[self.panGestureRecognizer view]]; CGFloat velocityValue = 0.0f; @@ -403,8 +408,8 @@ -(CGFloat)velocityMagnitude{ }else if (self.scrollDirection == UICollectionViewScrollDirectionHorizontal){ velocityValue = velocity.y; } + return velocityValue; - return fabsf(velocityValue); } -(LSSwipeToDeleteDirection)swipeToDeleteDirectionFromValue:(CGPoint)value{ @@ -436,7 +441,7 @@ -(BOOL)isVelocityInDeletionDirection:(CGPoint)velocity{ if (userTriggerredSwipeToDeleteVelocityDirection == LSSwipeToDeleteDirectionNone) { inDeletionDirection = NO; } - + return inDeletionDirection; }