Skip to content
This repository has been archived by the owner on Jul 12, 2019. It is now read-only.

Handle transparent background cell #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
54 changes: 41 additions & 13 deletions MCSwipeTableViewCell/MCSwipeTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,30 +156,32 @@ - (void)setupSwipingView {
return;
}

// If the content view background is transparent we get the background color.
BOOL isContentViewBackgroundClear = !self.contentView.backgroundColor;
if (isContentViewBackgroundClear) {
BOOL isBackgroundClear = [self.backgroundColor isEqual:[UIColor clearColor]];
self.contentView.backgroundColor = isBackgroundClear ? [UIColor whiteColor] :self.backgroundColor;
}

UIImage *contentViewScreenshotImage = [self imageWithView:self];

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

_colorIndicatorView = [[UIView alloc] initWithFrame:self.bounds];
_colorIndicatorView.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
_colorIndicatorView.backgroundColor = self.defaultColor ? self.defaultColor : [UIColor clearColor];
[self addSubview:_colorIndicatorView];

_slidingView = [[UIView alloc] init];
_slidingView.contentMode = UIViewContentModeCenter;
[_colorIndicatorView addSubview:_slidingView];
[self addSubview:_slidingView];

_contentScreenshotView = [[UIImageView alloc] initWithImage:contentViewScreenshotImage];
[self addSubview:_contentScreenshotView];

for (UIView *view in [self.subviews[0] subviews]) {
if (view == _contentScreenshotView || view == _colorIndicatorView || view == _slidingView) {
view.hidden = NO;
} else {
view.hidden = YES;
}
}

[self.contentScreenshotView.layer addObserver:self
forKeyPath:@"position"
options:NSKeyValueObservingOptionOld
context:NULL];
}

- (void)uninstallSwipingView {
Expand All @@ -195,6 +197,32 @@ - (void)uninstallSwipingView {

[_contentScreenshotView removeFromSuperview];
_contentScreenshotView = nil;

for (UIView *view in [self.subviews[0] subviews]) {
view.hidden = NO;
}

[self.contentScreenshotView.layer removeObserver:self
forKeyPath:@"position"];
}

- (void)observeValueForKeyPath:(NSString*)keyPath
ofObject:(id)object
change:(NSDictionary*)change
context:(void*)context {
if([keyPath isEqualToString:@"position"]) {
CGRect contentFrame = [self.contentScreenshotView.layer frame];
if (contentFrame.origin.x > 0.0f) {
CGRect colorFrame = self.colorIndicatorView.frame;
colorFrame.size.width = contentFrame.origin.x;
self.colorIndicatorView.frame = colorFrame;
} else {
CGRect colorFrame = self.colorIndicatorView.frame;
colorFrame.origin.x = contentFrame.origin.x + contentFrame.size.width;
colorFrame.size.width = contentFrame.size.width - contentFrame.origin.x;
self.colorIndicatorView.frame = colorFrame;
}
}
}

- (void)setViewOfSlidingView:(UIView *)slidingView {
Expand Down Expand Up @@ -255,7 +283,7 @@ - (void)setSwipeGestureWithView:(UIView *)view

- (void)handlePanGestureRecognizer:(UIPanGestureRecognizer *)gesture {

if (![self shouldDrag] || _isExited) {
if (!_shouldDrag || _isExited) {
return;
}

Expand Down