From d9b8a93eb53ef61dc09f2f95117ef71ffcc3d946 Mon Sep 17 00:00:00 2001 From: Paul Peelen Date: Tue, 10 Jun 2014 21:16:24 +0200 Subject: [PATCH 1/3] Added possibility to restore a swiped cell Using the method `restoreCell:delay:` you can restore the cell to its `0` position. --- JZSwipeCell/JZSwipeCell.h | 16 ++++++++++++++++ JZSwipeCell/JZSwipeCell.m | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/JZSwipeCell/JZSwipeCell.h b/JZSwipeCell/JZSwipeCell.h index 9d5d594..2b93600 100644 --- a/JZSwipeCell/JZSwipeCell.h +++ b/JZSwipeCell/JZSwipeCell.h @@ -100,6 +100,14 @@ typedef enum { */ - (void)swipeCell:(JZSwipeCell*)cell triggeredSwipeWithType:(JZSwipeType)swipeType; +/** + Notifies the delegate that a swipe has been restored to its original position. + @param cell The `JZSwipeCell` the swipe was detected in. Use `UITableView`'s `-indexPathForCell:` method to find the `NSIndexPath` for the cell. + @param The indicator wether the cell was restored with or without animation + @author Paul Peelen + */ +- (void)swipeCell:(JZSwipeCell*)cell didRestoreSwipeAmimated:(BOOL)animated; + @optional /** @@ -163,4 +171,12 @@ typedef enum { */ - (void)triggerSwipeWithType:(JZSwipeType)type; +/** + Restore the cell to its original position + @param animated BOOL If the restoration should be animated + @param animated CGFloat The duration of the delay before animating the restoration + @author Paul Peelen + */ +- (void)restoreCell:(BOOL)animated delay:(CGFloat)delay; + @end diff --git a/JZSwipeCell/JZSwipeCell.m b/JZSwipeCell/JZSwipeCell.m index 021c622..90fd46e 100644 --- a/JZSwipeCell/JZSwipeCell.m +++ b/JZSwipeCell/JZSwipeCell.m @@ -113,6 +113,26 @@ - (void)triggerSwipeWithType:(JZSwipeType)type [self runSwipeAnimationForType:type]; } +- (void)restoreCell:(BOOL)animated delay:(CGFloat)delay +{ + CGFloat newViewCenterX = self.dragStart; + CGFloat iconAlpha = 0; + + newViewCenterX = self.dragStart; + + [UIView animateWithDuration:0.12 + delay:delay + options:UIViewAnimationOptionCurveLinear + animations:^{ + self.contentView.center = CGPointMake(newViewCenterX, self.contentView.center.y); + self.icon.alpha = iconAlpha; + } completion:^(BOOL finished) { + if ([self.delegate respondsToSelector:@selector(swipeCell:didRestoreSwipeAmimated:)]) + [self.delegate swipeCell:self didRestoreSwipeAmimated:animated]; + self.dragStart = CGFLOAT_MIN; + }]; +} + #pragma mark - Private methods - (void)configureCell From 370e274f152058a31f4255d0b1e5ae8d5faaa0fc Mon Sep 17 00:00:00 2001 From: Paul Peelen Date: Tue, 10 Jun 2014 21:20:24 +0200 Subject: [PATCH 2/3] Updated the README for the restore method --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 765261f..e908258 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,10 @@ You can also trigger the swipe animation to run without any swipe occurring. JZSwipeCell *cell = (JZSwipeCell*)[self.tableView cellForRowAtIndexPath:indexPath]; [cell triggerSwipeWithType:JZSwipeTypeShortRight]; +To restore a swipe, you can simply use the `restoreCell:delay` method as such: + + [cell restoreCell:YES delay:0.1]; + Take a look at the examples for more info. There is one example of subclassing **JZSwipeCell** with a xib and another without. From c0c60c52329fe50a2a516a75b2c2956ce2ff3cb6 Mon Sep 17 00:00:00 2001 From: Paul Peelen Date: Tue, 10 Jun 2014 21:22:17 +0200 Subject: [PATCH 3/3] Fixed typo --- JZSwipeCell/JZSwipeCell.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JZSwipeCell/JZSwipeCell.h b/JZSwipeCell/JZSwipeCell.h index 2b93600..28f259f 100644 --- a/JZSwipeCell/JZSwipeCell.h +++ b/JZSwipeCell/JZSwipeCell.h @@ -103,7 +103,7 @@ typedef enum { /** Notifies the delegate that a swipe has been restored to its original position. @param cell The `JZSwipeCell` the swipe was detected in. Use `UITableView`'s `-indexPathForCell:` method to find the `NSIndexPath` for the cell. - @param The indicator wether the cell was restored with or without animation + @param The indicator whether the cell was restored with or without animation @author Paul Peelen */ - (void)swipeCell:(JZSwipeCell*)cell didRestoreSwipeAmimated:(BOOL)animated;