Skip to content

Commit f02bc82

Browse files
Fixes for #16: Turns out translation and velocity are two different things.
1 parent acef45e commit f02bc82

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

Library/DNSSwipeableCell.m

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,12 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogni
400400

401401
- (void)panThisCell:(UIPanGestureRecognizer *)recognizer
402402
{
403+
403404
CGPoint currentPoint = [recognizer translationInView:self.myContentView];
405+
CGPoint velocity = [recognizer velocityInView:self.myContentView];
404406

405-
//Check what direction the swipe is moving by checking the translation
406-
BOOL movingHorizontally = fabsf(self.panStartPoint.y) < fabsf(self.panStartPoint.x);
407+
//Check what direction the swipe is moving by checking the velocity
408+
BOOL movingHorizontally = fabsf(velocity.y) < fabsf(velocity.x);
407409

408410
switch (recognizer.state) {
409411
case UIGestureRecognizerStateBegan:
@@ -446,40 +448,36 @@ - (void)panThisCell:(UIPanGestureRecognizer *)recognizer
446448
}
447449
break;
448450
case UIGestureRecognizerStateEnded:
449-
if(movingHorizontally) {
450-
if (self.startingRightLayoutConstraintConstant == 0) {
451-
//We were opening
452-
CGFloat halfWidth = [self halfOfFirstButtonWidth];
453-
if (halfWidth != 0 && //Handle case where cell is already offscreen.
454-
self.contentViewRightConstraint.constant >= halfWidth) {
455-
//Open all the way
456-
[self setConstraintsToShowAllButtons:YES notifyDelegateDidOpen:YES];
457-
} else {
458-
//Re-close
459-
[self resetConstraintContstantsToZero:YES notifyDelegateDidClose:YES];
460-
}
451+
if (self.startingRightLayoutConstraintConstant == 0) {
452+
//We were opening
453+
CGFloat halfWidth = [self halfOfFirstButtonWidth];
454+
if (halfWidth != 0 && //Handle case where cell is already offscreen.
455+
self.contentViewRightConstraint.constant >= halfWidth) {
456+
//Open all the way
457+
[self setConstraintsToShowAllButtons:YES notifyDelegateDidOpen:YES];
461458
} else {
459+
//Re-close
460+
[self resetConstraintContstantsToZero:YES notifyDelegateDidClose:YES];
461+
}
462+
} else {
462463
//We were closing
463-
if (self.contentViewRightConstraint.constant >= [self halfOfLastButtonXPosition]) {
464-
//Re-open all the way
465-
[self setConstraintsToShowAllButtons:YES notifyDelegateDidOpen:YES];
466-
} else {
467-
//Close
468-
[self resetConstraintContstantsToZero:YES notifyDelegateDidClose:YES];
469-
}
464+
if (self.contentViewRightConstraint.constant >= [self halfOfLastButtonXPosition]) {
465+
//Re-open all the way
466+
[self setConstraintsToShowAllButtons:YES notifyDelegateDidOpen:YES];
467+
} else {
468+
//Close
469+
[self resetConstraintContstantsToZero:YES notifyDelegateDidClose:YES];
470470
}
471471
}
472472
break;
473473
case UIGestureRecognizerStateCancelled:
474-
if(movingHorizontally) {
475-
// Started by moving horizontally
476-
if (self.startingRightLayoutConstraintConstant == 0) {
477-
//We were closed - reset everything to 0
478-
[self resetConstraintContstantsToZero:YES notifyDelegateDidClose:YES];
479-
} else {
480-
//We were open - reset to the open state
481-
[self setConstraintsToShowAllButtons:YES notifyDelegateDidOpen:YES];
482-
}
474+
// Started by moving horizontally
475+
if (self.startingRightLayoutConstraintConstant == 0) {
476+
//We were closed - reset everything to 0
477+
[self resetConstraintContstantsToZero:YES notifyDelegateDidClose:YES];
478+
} else {
479+
//We were open - reset to the open state
480+
[self setConstraintsToShowAllButtons:YES notifyDelegateDidOpen:YES];
483481
}
484482
break;
485483

0 commit comments

Comments
 (0)