Skip to content
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
3 changes: 2 additions & 1 deletion MGSwipeTableCell/MGSwipeTableCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ typedef NS_ENUM(NSInteger, MGSwipeEasingFunction) {
/** optional to use contentView alternative. Use this property instead of contentView to support animated views while swiping */
@property (nonatomic, strong, readonly, nonnull) UIView * swipeContentView;

/**
- (UIView *)swipeOverlayContainerView;
/**
* Left and right swipe buttons and its settings.
* Buttons can be any kind of UIView but it's recommended to use the convenience MGSwipeButton class
*/
Expand Down
40 changes: 22 additions & 18 deletions MGSwipeTableCell/MGSwipeTableCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,8 @@ -(BOOL) isRTLLocale
-(void) fixRegionAndAccesoryViews
{
//Fix right to left layout direction for arabic and hebrew languagues
if (self.bounds.size.width != self.contentView.bounds.size.width && [self isRTLLocale]) {
_swipeOverlay.frame = CGRectMake(-self.bounds.size.width + self.contentView.bounds.size.width, 0, _swipeOverlay.bounds.size.width, _swipeOverlay.bounds.size.height);
if (self.swipeOverlayContainerView.bounds.size.width != self.swipeOverlayContainerView.bounds.size.width && [self isRTLLocale]) {
_swipeOverlay.frame = CGRectMake(-self.swipeOverlayContainerView.bounds.size.width + self.swipeOverlayContainerView.bounds.size.width, 0, _swipeOverlay.bounds.size.width, _swipeOverlay.bounds.size.height);
}
}

Expand All @@ -754,11 +754,11 @@ -(UIEdgeInsets) getSafeInsets {
-(UIView *) swipeContentView
{
if (!_swipeContentView) {
_swipeContentView = [[UIView alloc] initWithFrame:self.contentView.bounds];
_swipeContentView = [[UIView alloc] initWithFrame:self.swipeOverlayContainerView.bounds];
_swipeContentView.backgroundColor = [UIColor clearColor];
_swipeContentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_swipeContentView.layer.zPosition = 9;
[self.contentView addSubview:_swipeContentView];
[self.swipeOverlayContainerView addSubview:_swipeContentView];
}
return _swipeContentView;
}
Expand All @@ -767,11 +767,11 @@ -(void) layoutSubviews
{
[super layoutSubviews];
if (_swipeContentView) {
_swipeContentView.frame = self.contentView.bounds;
_swipeContentView.frame = self.swipeOverlayContainerView.bounds;
}
if (_swipeOverlay) {
CGSize prevSize = _swipeView.bounds.size;
_swipeOverlay.frame = CGRectMake(0, 0, self.bounds.size.width, self.contentView.bounds.size.height);
_swipeOverlay.frame = CGRectMake(0, 0, self.swipeOverlayContainerView.bounds.size.width, self.swipeOverlayContainerView.bounds.size.height);
[self fixRegionAndAccesoryViews];
if (_swipeView.image && !CGSizeEqualToSize(prevSize, _swipeOverlay.bounds.size)) {
//refresh safeInsets in situations like layout change, orientation change, table resize, etc.
Expand Down Expand Up @@ -813,7 +813,7 @@ -(void) createSwipeViewIfNeeded
{
UIEdgeInsets safeInsets = [self getSafeInsets];
if (!_swipeOverlay) {
_swipeOverlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.contentView.bounds.size.height)];
_swipeOverlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.swipeOverlayContainerView.frame.size.width, self.swipeOverlayContainerView.bounds.size.height)];
[self fixRegionAndAccesoryViews];
_swipeOverlay.hidden = YES;
_swipeOverlay.backgroundColor = [self backgroundColorForSwipe];
Expand All @@ -823,7 +823,7 @@ -(void) createSwipeViewIfNeeded
_swipeView.contentMode = UIViewContentModeCenter;
_swipeView.clipsToBounds = YES;
[_swipeOverlay addSubview:_swipeView];
[self.contentView addSubview:_swipeOverlay];
[self.swipeOverlayContainerView addSubview:_swipeOverlay];
}

[self fetchButtonsIfNeeded];
Expand Down Expand Up @@ -877,8 +877,8 @@ - (void) showSwipeOverlayIfNeeded
}

// snapshot cell without separator
CGSize cropSize = CGSizeMake(self.bounds.size.width, self.contentView.bounds.size.height);
_swipeView.image = [self imageFromView:self cropSize:cropSize];
CGSize cropSize = CGSizeMake(self.swipeOverlayContainerView.bounds.size.width, self.swipeOverlayContainerView.bounds.size.height);
_swipeView.image = [self imageFromView:self.swipeOverlayContainerView cropSize:cropSize];

_swipeOverlay.hidden = NO;
if (_swipeContentView)
Expand Down Expand Up @@ -915,7 +915,7 @@ -(void) hideSwipeOverlayIfNeededIncludingReselect: (BOOL) reselectCellIfNeeded
_swipeView.image = nil;
if (_swipeContentView) {
[_swipeContentView removeFromSuperview];
[self.contentView addSubview:_swipeContentView];
[self.swipeOverlayContainerView addSubview:_swipeContentView];
}

if (_tableInputOverlay) {
Expand Down Expand Up @@ -1054,13 +1054,13 @@ -(void) setAccesoryViewsHidden: (BOOL) hidden
if (self.accessoryView) {
self.accessoryView.hidden = hidden;
}
for (UIView * view in self.contentView.superview.subviews) {
if (view != self.contentView && ([view isKindOfClass:[UIButton class]] || [NSStringFromClass(view.class) rangeOfString:@"Disclosure"].location != NSNotFound)) {
for (UIView * view in self.swipeOverlayContainerView.superview.subviews) {
if (view != self.swipeOverlayContainerView && ([view isKindOfClass:[UIButton class]] || [NSStringFromClass(view.class) rangeOfString:@"Disclosure"].location != NSNotFound)) {
view.hidden = hidden;
}
}

for (UIView * view in self.contentView.subviews) {
for (UIView * view in self.swipeOverlayContainerView.subviews) {
if (view == _swipeOverlay || view == _swipeContentView) continue;
if (hidden && !view.hidden) {
view.hidden = YES;
Expand All @@ -1081,8 +1081,8 @@ -(UIColor *) backgroundColorForSwipe
if (_swipeBackgroundColor) {
return _swipeBackgroundColor; //user defined color
}
else if (self.contentView.backgroundColor && ![self.contentView.backgroundColor isEqual:[UIColor clearColor]]) {
return self.contentView.backgroundColor;
else if (self.swipeOverlayContainerView.backgroundColor && ![self.swipeOverlayContainerView.backgroundColor isEqual:[UIColor clearColor]]) {
return self.swipeOverlayContainerView.backgroundColor;
}
else if (self.backgroundColor) {
return self.backgroundColor;
Expand All @@ -1101,6 +1101,10 @@ -(UITableView *) parentTable
}
return nil;
}

- (UIView *)swipeOverlayContainerView {
return self.contentView;
}

-(void) updateState: (MGSwipeState) newState;
{
Expand Down Expand Up @@ -1176,7 +1180,7 @@ - (void)setSwipeOffset:(CGFloat) newOffset;
bool expand = expansions[i].buttonIndex >= 0 && offset > view.bounds.size.width * expansions[i].threshold;
if (expand) {
[view expandToOffset:offset settings:expansions[i]];
_targetOffset = expansions[i].fillOnTrigger ? self.bounds.size.width * sign : 0;
_targetOffset = expansions[i].fillOnTrigger ? self.swipeOverlayContainerView.bounds.size.width * sign : 0;
_activeExpansion = view;
[self updateState:i ? MGSwipeStateExpandingRightToLeft : MGSwipeStateExpandingLeftToRight];
}
Expand Down Expand Up @@ -1506,7 +1510,7 @@ - (NSInteger)accessibilityElementCount {
}

- (id)accessibilityElementAtIndex:(NSInteger)index {
return _swipeOffset == 0 ? [super accessibilityElementAtIndex:index] : self.contentView;
return _swipeOffset == 0 ? [super accessibilityElementAtIndex:index] : self.swipeOverlayContainerView;
}

- (NSInteger)indexOfAccessibilityElement:(id)element {
Expand Down