Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added restore functionality #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions JZSwipeCell/JZSwipeCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Paul@PaulPeelen.com>
*/
- (void)swipeCell:(JZSwipeCell*)cell didRestoreSwipeAmimated:(BOOL)animated;

@optional

/**
Expand Down Expand Up @@ -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 <Paul@PaulPeelen.com>
*/
- (void)restoreCell:(BOOL)animated delay:(CGFloat)delay;

@end
20 changes: 20 additions & 0 deletions JZSwipeCell/JZSwipeCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down