Skip to content
This repository was archived by the owner on Jul 12, 2019. It is now read-only.
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
6 changes: 6 additions & 0 deletions MCSwipeTableViewCell/MCSwipeTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ typedef void (^MCSwipeCompletionBlock)(MCSwipeTableViewCell *cell, MCSwipeTableV
/** Boolean to enable/disable the animation of the view during the swipe. */
@property (nonatomic, assign, readwrite) BOOL shouldAnimateIcons;

/** Insets for swipeable view */
@property (nonatomic, assign, readwrite) UIEdgeInsets swipableViewInsets;

/** Boolean to enable/disable fully hiding cell after swipe finished */
@property (nonatomic, assign, readwrite) BOOL hideAfterSwipe;

/**
* Configures the properties of a cell.
*
Expand Down
20 changes: 16 additions & 4 deletions MCSwipeTableViewCell/MCSwipeTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ - (void)initDefaults {
_dragging = NO;
_shouldDrag = YES;
_shouldAnimateIcons = YES;
_swipableViewInsets = UIEdgeInsetsZero;
_hideAfterSwipe = NO;

_firstTrigger = kMCStop1;
_secondTrigger = kMCStop2;
Expand Down Expand Up @@ -163,13 +165,13 @@ - (void)setupSwipingView {
self.contentView.backgroundColor = isBackgroundClear ? [UIColor whiteColor] :self.backgroundColor;
}

UIImage *contentViewScreenshotImage = [self imageWithView:self];
UIImage *contentViewScreenshotImage = [self imageWithView:self size:CGSizeMake(self.frame.size.width - _swipableViewInsets.left - _swipableViewInsets.right, self.frame.size.height - _swipableViewInsets.top - _swipableViewInsets.bottom)];

if (isContentViewBackgroundClear) {
self.contentView.backgroundColor = nil;
}

_colorIndicatorView = [[UIView alloc] initWithFrame:self.bounds];
_colorIndicatorView = [[UIView alloc] initWithFrame:CGRectMake(_swipableViewInsets.left, _swipableViewInsets.top, contentViewScreenshotImage.size.width, contentViewScreenshotImage.size.height)];
_colorIndicatorView.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
_colorIndicatorView.backgroundColor = self.defaultColor ? self.defaultColor : [UIColor clearColor];
[self addSubview:_colorIndicatorView];
Expand Down Expand Up @@ -313,6 +315,7 @@ - (void)handlePanGestureRecognizer:(UIPanGestureRecognizer *)gesture {

else {
[self swipeToOriginWithCompletion:^{
[self hideSeparatorIfNeeded];
[self executeCompletionBlock];
}];
}
Expand Down Expand Up @@ -593,10 +596,19 @@ - (void)moveWithDuration:(NSTimeInterval)duration andDirection:(MCSwipeTableView
_slidingView.alpha = 0;
[self slideViewWithPercentage:percentage view:_activeView isDragging:self.shouldAnimateIcons];
} completion:^(BOOL finished) {
[self hideSeparatorIfNeeded];
[self executeCompletionBlock];
}];
}

- (void)hideSeparatorIfNeeded {
if (_hideAfterSwipe) {
_colorIndicatorView.frame = self.bounds;
[_colorIndicatorView setNeedsLayout];
[_colorIndicatorView layoutIfNeeded];
}
}

- (void)swipeToOriginWithCompletion:(void(^)(void))completion {
CGFloat bounceDistance = kMCBounceAmplitude * _currentPercentage;

Expand Down Expand Up @@ -664,9 +676,9 @@ - (void)swipeToOriginWithCompletion:(void(^)(void))completion {

#pragma mark - Utilities

- (UIImage *)imageWithView:(UIView *)view {
- (UIImage *)imageWithView:(UIView *)view size:(CGSize)size {
CGFloat scale = [[UIScreen mainScreen] scale];
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, scale);
UIGraphicsBeginImageContextWithOptions(size, NO, scale);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Expand Down