From f86cc5dde4c84bdbc43247ba789b715b61442976 Mon Sep 17 00:00:00 2001 From: Dan Cohn Date: Sat, 18 Oct 2014 12:54:13 -0400 Subject: [PATCH 1/2] Option to immediately hide other cells With this option, as soon as a cell begins to scroll, all other cells will immediately return to center instead of waiting until dragging ends --- SWTableViewCell/PodFiles/SWTableViewCell.h | 1 + SWTableViewCell/PodFiles/SWTableViewCell.m | 12 ++++++++++++ SWTableViewCell/ViewController.m | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/SWTableViewCell/PodFiles/SWTableViewCell.h b/SWTableViewCell/PodFiles/SWTableViewCell.h index 50b2d11..f1ecf33 100644 --- a/SWTableViewCell/PodFiles/SWTableViewCell.h +++ b/SWTableViewCell/PodFiles/SWTableViewCell.h @@ -29,6 +29,7 @@ typedef NS_ENUM(NSInteger, SWCellState) - (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index; - (void)swipeableTableViewCell:(SWTableViewCell *)cell scrollingToState:(SWCellState)state; - (BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell *)cell; +- (BOOL)swipeableTableViewCellShouldHideUtilityButtonsImmediatelyOnSwipe:(SWTableViewCell *)cell; - (BOOL)swipeableTableViewCell:(SWTableViewCell *)cell canSwipeToState:(SWCellState)state; - (void)swipeableTableViewCellDidEndScrolling:(SWTableViewCell *)cell; diff --git a/SWTableViewCell/PodFiles/SWTableViewCell.m b/SWTableViewCell/PodFiles/SWTableViewCell.m index 1c6e57c..697b893 100644 --- a/SWTableViewCell/PodFiles/SWTableViewCell.m +++ b/SWTableViewCell/PodFiles/SWTableViewCell.m @@ -742,6 +742,18 @@ -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL) } +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView +{ + if ([self.delegate respondsToSelector:@selector(swipeableTableViewCellShouldHideUtilityButtonsImmediatelyOnSwipe:)]) + { + for (SWTableViewCell *cell in [self.containingTableView visibleCells]) { + if (cell != self && [cell isKindOfClass:[SWTableViewCell class]] && [self.delegate swipeableTableViewCellShouldHideUtilityButtonsImmediatelyOnSwipe:cell]) { + [cell hideUtilityButtonsAnimated:YES]; + } + } + } +} + #pragma mark - UIGestureRecognizerDelegate - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer diff --git a/SWTableViewCell/ViewController.m b/SWTableViewCell/ViewController.m index e2ed5f9..02b2c1f 100644 --- a/SWTableViewCell/ViewController.m +++ b/SWTableViewCell/ViewController.m @@ -271,6 +271,11 @@ - (BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell * return YES; } +- (BOOL)swipeableTableViewCellShouldHideUtilityButtonsImmediatelyOnSwipe:(SWTableViewCell *)cell +{ + return NO; +} + - (BOOL)swipeableTableViewCell:(SWTableViewCell *)cell canSwipeToState:(SWCellState)state { switch (state) { From 40ddc6669b221eee77cfb375f5a81be3a215c39b Mon Sep 17 00:00:00 2001 From: Dan Cohn Date: Sun, 19 Oct 2014 17:43:02 -0400 Subject: [PATCH 2/2] Cells now hide immediately by default with no extra delegate method --- SWTableViewCell/PodFiles/SWTableViewCell.h | 1 - SWTableViewCell/PodFiles/SWTableViewCell.m | 16 ++-------------- SWTableViewCell/ViewController.m | 5 ----- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/SWTableViewCell/PodFiles/SWTableViewCell.h b/SWTableViewCell/PodFiles/SWTableViewCell.h index f1ecf33..50b2d11 100644 --- a/SWTableViewCell/PodFiles/SWTableViewCell.h +++ b/SWTableViewCell/PodFiles/SWTableViewCell.h @@ -29,7 +29,6 @@ typedef NS_ENUM(NSInteger, SWCellState) - (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index; - (void)swipeableTableViewCell:(SWTableViewCell *)cell scrollingToState:(SWCellState)state; - (BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell *)cell; -- (BOOL)swipeableTableViewCellShouldHideUtilityButtonsImmediatelyOnSwipe:(SWTableViewCell *)cell; - (BOOL)swipeableTableViewCell:(SWTableViewCell *)cell canSwipeToState:(SWCellState)state; - (void)swipeableTableViewCellDidEndScrolling:(SWTableViewCell *)cell; diff --git a/SWTableViewCell/PodFiles/SWTableViewCell.m b/SWTableViewCell/PodFiles/SWTableViewCell.m index 697b893..30e5a4d 100644 --- a/SWTableViewCell/PodFiles/SWTableViewCell.m +++ b/SWTableViewCell/PodFiles/SWTableViewCell.m @@ -655,18 +655,6 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi [self.delegate swipeableTableViewCell:self scrollingToState:_cellState]; } - if (_cellState != kCellStateCenter) - { - if ([self.delegate respondsToSelector:@selector(swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:)]) - { - for (SWTableViewCell *cell in [self.containingTableView visibleCells]) { - if (cell != self && [cell isKindOfClass:[SWTableViewCell class]] && [self.delegate swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:cell]) { - [cell hideUtilityButtonsAnimated:YES]; - } - } - } - } - *targetContentOffset = [self contentOffsetForCellState:_cellState]; } @@ -744,10 +732,10 @@ -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL) - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { - if ([self.delegate respondsToSelector:@selector(swipeableTableViewCellShouldHideUtilityButtonsImmediatelyOnSwipe:)]) + if ([self.delegate respondsToSelector:@selector(swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:)]) { for (SWTableViewCell *cell in [self.containingTableView visibleCells]) { - if (cell != self && [cell isKindOfClass:[SWTableViewCell class]] && [self.delegate swipeableTableViewCellShouldHideUtilityButtonsImmediatelyOnSwipe:cell]) { + if (cell != self && [cell isKindOfClass:[SWTableViewCell class]] && [self.delegate swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:cell]) { [cell hideUtilityButtonsAnimated:YES]; } } diff --git a/SWTableViewCell/ViewController.m b/SWTableViewCell/ViewController.m index 02b2c1f..e2ed5f9 100644 --- a/SWTableViewCell/ViewController.m +++ b/SWTableViewCell/ViewController.m @@ -271,11 +271,6 @@ - (BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell * return YES; } -- (BOOL)swipeableTableViewCellShouldHideUtilityButtonsImmediatelyOnSwipe:(SWTableViewCell *)cell -{ - return NO; -} - - (BOOL)swipeableTableViewCell:(SWTableViewCell *)cell canSwipeToState:(SWCellState)state { switch (state) {