diff --git a/JZSwipeCell/JZSwipeCell.h b/JZSwipeCell/JZSwipeCell.h index 9d5d594..28f259f 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 whether 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 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.