From e2564cab52bd1bf0a462b0e0d11f59c285fffa92 Mon Sep 17 00:00:00 2001 From: Lance Watson Date: Wed, 25 Oct 2017 13:04:53 +0200 Subject: [PATCH 1/5] added content offsets --- MGSwipeTableCell/MGSwipeTableCell.h | 5 ++++ MGSwipeTableCell/MGSwipeTableCell.m | 38 +++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/MGSwipeTableCell/MGSwipeTableCell.h b/MGSwipeTableCell/MGSwipeTableCell.h index 1a9a388..62f37e0 100644 --- a/MGSwipeTableCell/MGSwipeTableCell.h +++ b/MGSwipeTableCell/MGSwipeTableCell.h @@ -218,6 +218,11 @@ 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; +/** + * Abacus property to allow grouped cells + * + */ +@property (nonatomic, assign) UIEdgeInsets contentInsets; /** * 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 diff --git a/MGSwipeTableCell/MGSwipeTableCell.m b/MGSwipeTableCell/MGSwipeTableCell.m index 18d6753..92d4a72 100644 --- a/MGSwipeTableCell/MGSwipeTableCell.m +++ b/MGSwipeTableCell/MGSwipeTableCell.m @@ -720,16 +720,13 @@ -(void) fetchButtonsIfNeeded -(void) createSwipeViewIfNeeded { if (!_swipeOverlay) { - _swipeOverlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.contentView.bounds.size.height)]; + _swipeOverlay = [[UIView alloc] initWithFrame:CGRectMake(12, 0, self.bounds.size.width-24, self.contentView.bounds.size.height)]; [self fixRegionAndAccesoryViews]; _swipeOverlay.hidden = YES; _swipeOverlay.backgroundColor = [self backgroundColorForSwipe]; _swipeOverlay.layer.zPosition = 10; //force render on top of the contentView; - _swipeView = [[UIImageView alloc] initWithFrame:_swipeOverlay.bounds]; - _swipeView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - _swipeView.contentMode = UIViewContentModeCenter; - _swipeView.clipsToBounds = YES; - [_swipeOverlay addSubview:_swipeView]; + [_swipeOverlay setAccessibilityLabel:@"Swipe Overlay"]; + _swipeOverlay.clipsToBounds = YES; [self.contentView addSubview:_swipeOverlay]; } @@ -748,8 +745,20 @@ -(void) createSwipeViewIfNeeded _rightView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight; [_swipeOverlay addSubview:_rightView]; } + if(!_swipeView) + { + _swipeView = [[UIImageView alloc] initWithFrame:_swipeOverlay.bounds]; + _swipeView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + _swipeView.contentMode = UIViewContentModeCenter; + [_swipeView setAccessibilityLabel:@"Swipe View"]; + [_swipeOverlay addSubview:_swipeView]; + } + } +-(void) updateSwipeFrames { + +} - (void) showSwipeOverlayIfNeeded { @@ -918,6 +927,8 @@ -(UIView *) hitTest:(CGPoint)point withEvent:(UIEvent *)event - (UIImage *)imageFromView:(UIView *)view cropSize:(CGSize)cropSize{ UIGraphicsBeginImageContextWithOptions(cropSize, NO, [[UIScreen mainScreen] scale]); +// [self.backgroundView drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES]; +// [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES]; [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); @@ -1030,8 +1041,19 @@ - (void)setSwipeOffset:(CGFloat) newOffset; } BOOL onlyButtons = activeSettings.onlySwipeButtons; - _swipeView.transform = CGAffineTransformMakeTranslation(onlyButtons ? 0 : _swipeOffset, 0); - + // update swipe frames + if(_swipeOffset > 0) + { + _swipeOverlay.frame = CGRectMake(self.contentInsets.left, 0, self.bounds.size.width-self.contentInsets.left, self.contentView.bounds.size.height); + } else { + _swipeOverlay.frame = CGRectMake(0, 0, self.bounds.size.width-self.contentInsets.right, self.contentView.bounds.size.height); + } + + CGRect swipeViewBounds = _swipeOverlay.bounds; + swipeViewBounds.origin.x = onlyButtons ? 0 : _swipeOffset - _swipeOverlay.frame.origin.x, 0; + swipeViewBounds.size.width = self.bounds.size.width; + _swipeView.frame = swipeViewBounds; + //animate existing buttons MGSwipeButtonsView* but[2] = {_leftView, _rightView}; MGSwipeSettings* settings[2] = {_leftSwipeSettings, _rightSwipeSettings}; From 864270421f276020102d886ccd91eb7056c800f8 Mon Sep 17 00:00:00 2001 From: Lance Watson Date: Wed, 25 Oct 2017 17:13:44 +0200 Subject: [PATCH 2/5] better support for corner radii (still some issues) --- MGSwipeTableCell/MGSwipeTableCell.h | 4 +++- MGSwipeTableCell/MGSwipeTableCell.m | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/MGSwipeTableCell/MGSwipeTableCell.h b/MGSwipeTableCell/MGSwipeTableCell.h index 62f37e0..6bbafc5 100644 --- a/MGSwipeTableCell/MGSwipeTableCell.h +++ b/MGSwipeTableCell/MGSwipeTableCell.h @@ -223,7 +223,9 @@ typedef NS_ENUM(NSInteger, MGSwipeEasingFunction) { * */ @property (nonatomic, assign) UIEdgeInsets contentInsets; -/** +@property (nonatomic, assign) CGFloat cornerRadius; + +/** * 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 */ diff --git a/MGSwipeTableCell/MGSwipeTableCell.m b/MGSwipeTableCell/MGSwipeTableCell.m index 92d4a72..eb09262 100644 --- a/MGSwipeTableCell/MGSwipeTableCell.m +++ b/MGSwipeTableCell/MGSwipeTableCell.m @@ -1045,8 +1045,18 @@ - (void)setSwipeOffset:(CGFloat) newOffset; if(_swipeOffset > 0) { _swipeOverlay.frame = CGRectMake(self.contentInsets.left, 0, self.bounds.size.width-self.contentInsets.left, self.contentView.bounds.size.height); + _leftView.layer.cornerRadius = self.cornerRadius; + _leftView.layer.masksToBounds = YES; + _rightView.layer.cornerRadius = self.cornerRadius; + _rightView.layer.masksToBounds = YES; + } else { _swipeOverlay.frame = CGRectMake(0, 0, self.bounds.size.width-self.contentInsets.right, self.contentView.bounds.size.height); + _leftView.layer.cornerRadius = self.cornerRadius; + _leftView.layer.masksToBounds = YES; + _rightView.layer.cornerRadius = self.cornerRadius; + _rightView.layer.masksToBounds = YES; + } CGRect swipeViewBounds = _swipeOverlay.bounds; From caa5ac3d0069c77f7e8041999e8bd2f5dded3349 Mon Sep 17 00:00:00 2001 From: Lance Watson Date: Thu, 26 Oct 2017 09:37:48 +0200 Subject: [PATCH 3/5] fixed disappearing stuff --- MGSwipeTableCell/MGSwipeTableCell.m | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/MGSwipeTableCell/MGSwipeTableCell.m b/MGSwipeTableCell/MGSwipeTableCell.m index eb09262..8459be6 100644 --- a/MGSwipeTableCell/MGSwipeTableCell.m +++ b/MGSwipeTableCell/MGSwipeTableCell.m @@ -728,8 +728,13 @@ -(void) createSwipeViewIfNeeded [_swipeOverlay setAccessibilityLabel:@"Swipe Overlay"]; _swipeOverlay.clipsToBounds = YES; [self.contentView addSubview:_swipeOverlay]; + _swipeView = [[UIImageView alloc] initWithFrame:_swipeOverlay.bounds]; + _swipeView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + _swipeView.contentMode = UIViewContentModeCenter; + [_swipeView setAccessibilityLabel:@"Swipe View"]; + [_swipeOverlay addSubview:_swipeView]; } - + [self fetchButtonsIfNeeded]; if (!_leftView && _leftButtons.count > 0) { _leftView = [[MGSwipeButtonsView alloc] initWithButtons:_leftButtons direction:MGSwipeDirectionLeftToRight differentWidth:_allowsButtonsWithDifferentWidth buttonsDistance:_leftSwipeSettings.buttonsDistance]; @@ -745,14 +750,7 @@ -(void) createSwipeViewIfNeeded _rightView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight; [_swipeOverlay addSubview:_rightView]; } - if(!_swipeView) - { - _swipeView = [[UIImageView alloc] initWithFrame:_swipeOverlay.bounds]; - _swipeView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - _swipeView.contentMode = UIViewContentModeCenter; - [_swipeView setAccessibilityLabel:@"Swipe View"]; - [_swipeOverlay addSubview:_swipeView]; - } + [_swipeOverlay bringSubviewToFront:_swipeView]; } From a275fff76b5252dd5d4a3c50412a1015b172eac4 Mon Sep 17 00:00:00 2001 From: Roger Misteli Date: Fri, 23 Aug 2019 08:52:40 +0200 Subject: [PATCH 4/5] quick fix for iOS 13 with crashing table view cell --- MGSwipeTableCell/MGSwipeTableCell.m | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/MGSwipeTableCell/MGSwipeTableCell.m b/MGSwipeTableCell/MGSwipeTableCell.m index 8459be6..6e03306 100644 --- a/MGSwipeTableCell/MGSwipeTableCell.m +++ b/MGSwipeTableCell/MGSwipeTableCell.m @@ -603,7 +603,7 @@ -(void) awakeFromNib -(void) dealloc { - [self hideSwipeOverlayIfNeeded]; + [self hideSwipeOverlayIfNeeded:YES]; } -(void) initViews: (BOOL) cleanButtons @@ -802,7 +802,7 @@ - (void) showSwipeOverlayIfNeeded [self addGestureRecognizer:_tapRecognizer]; } --(void) hideSwipeOverlayIfNeeded +-(void) hideSwipeOverlayIfNeeded:(BOOL) fromDealloc { if (!_overlayEnabled) { return; @@ -820,7 +820,9 @@ -(void) hideSwipeOverlayIfNeeded _tableInputOverlay = nil; } - self.selectionStyle = _previusSelectionStyle; + if (!fromDealloc) { + self.selectionStyle = _previusSelectionStyle; + } NSArray * selectedRows = self.parentTable.indexPathsForSelectedRows; if ([selectedRows containsObject:[self.parentTable indexPathForCell:self]]) { self.selected = NO; //Hack: in some iOS versions setting the selected property to YES own isn't enough to force the cell to redraw the chosen selectionStyle @@ -871,7 +873,7 @@ -(void) refreshButtons: (BOOL) usingDelegate -(void) willMoveToSuperview:(UIView *)newSuperview; { if (newSuperview == nil) { //remove the table overlay when a cell is removed from the table - [self hideSwipeOverlayIfNeeded]; + [self hideSwipeOverlayIfNeeded:YES]; } } @@ -1026,7 +1028,7 @@ - (void)setSwipeOffset:(CGFloat) newOffset; [_leftView endExpansionAnimated:NO]; if (_rightView) [_rightView endExpansionAnimated:NO]; - [self hideSwipeOverlayIfNeeded]; + [self hideSwipeOverlayIfNeeded:NO]; _targetOffset = 0; [self updateState:MGSwipeStateNone]; return; From 7afdabb6b2d22cdd01e0c7cbe7f19e0b76b8b0f2 Mon Sep 17 00:00:00 2001 From: fuggly Date: Thu, 18 Jun 2020 08:56:02 +0200 Subject: [PATCH 5/5] + Fix for insets actually working the way they're supposed to --- MGSwipeTableCell/MGSwipeTableCell.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MGSwipeTableCell/MGSwipeTableCell.m b/MGSwipeTableCell/MGSwipeTableCell.m index acef348..66f08ab 100644 --- a/MGSwipeTableCell/MGSwipeTableCell.m +++ b/MGSwipeTableCell/MGSwipeTableCell.m @@ -813,7 +813,7 @@ -(void) createSwipeViewIfNeeded { UIEdgeInsets safeInsets = [self getSafeInsets]; if (!_swipeOverlay) { - _swipeOverlay = [[UIView alloc] initWithFrame:CGRectMake(12, 0, self.bounds.size.width-24, self.contentView.bounds.size.height)]; + _swipeOverlay = [[UIView alloc] initWithFrame:CGRectMake(self.contentInsets.left, 0, self.bounds.size.width-self.contentInsets.left - self.contentInsets.right, self.contentView.bounds.size.height)]; [self fixRegionAndAccesoryViews]; _swipeOverlay.hidden = YES; _swipeOverlay.backgroundColor = [self backgroundColorForSwipe];