From d28341a8067e6978eace1f8372b7d04c7df8d890 Mon Sep 17 00:00:00 2001 From: Simon Germain Date: Mon, 17 Jul 2017 15:23:33 -0400 Subject: [PATCH] Added demo method that will partially expand the swipable cell and retract it --- MGSwipeTableCell/MGSwipeTableCell.h | 1 + MGSwipeTableCell/MGSwipeTableCell.m | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/MGSwipeTableCell/MGSwipeTableCell.h b/MGSwipeTableCell/MGSwipeTableCell.h index 1a9a388..3a51c1f 100644 --- a/MGSwipeTableCell/MGSwipeTableCell.h +++ b/MGSwipeTableCell/MGSwipeTableCell.h @@ -263,6 +263,7 @@ typedef NS_ENUM(NSInteger, MGSwipeEasingFunction) { -(void) setSwipeOffset:(CGFloat)offset animated: (BOOL) animated completion:(nullable void(^)(BOOL finished)) completion; -(void) setSwipeOffset:(CGFloat)offset animation: (nullable MGSwipeAnimation *) animation completion:(nullable void(^)(BOOL finished)) completion; -(void) expandSwipe: (MGSwipeDirection) direction animated: (BOOL) animated; +-(void) demoSwipe: (MGSwipeDirection) direction expandDistance: (NSInteger) distance; /** Refresh method to be used when you want to update the cell contents while the user is swiping */ -(void) refreshContentView; diff --git a/MGSwipeTableCell/MGSwipeTableCell.m b/MGSwipeTableCell/MGSwipeTableCell.m index 267f14b..cfd762c 100644 --- a/MGSwipeTableCell/MGSwipeTableCell.m +++ b/MGSwipeTableCell/MGSwipeTableCell.m @@ -1092,6 +1092,27 @@ -(void) showSwipe: (MGSwipeDirection) direction animated: (BOOL) animated comple } } +-(void) demoSwipe: (MGSwipeDirection) direction expandDistance: (NSInteger) distance { + CGFloat s = direction == MGSwipeDirectionLeftToRight ? 1.0 : -1.0; + MGSwipeExpansionSettings* expSetting = direction == MGSwipeDirectionLeftToRight ? _leftExpansion : _rightExpansion; + + if(!_activeExpansion) { + [self createSwipeViewIfNeeded]; + _allowSwipeLeftToRight = _leftButtons.count > 0; + _allowSwipeRightToLeft = _rightButtons.count > 0; + UIView * buttonsView = direction == MGSwipeDirectionLeftToRight ? _leftView : _rightView; + + if (buttonsView) { + __weak MGSwipeButtonsView * expansionView = direction == MGSwipeDirectionLeftToRight ? _leftView : _rightView; + __weak MGSwipeTableCell * weakself = self; + [self setSwipeOffset:distance * s * expSetting.threshold * 2 animation:expSetting.triggerAnimation completion:^(BOOL finished){ + [expansionView endExpansionAnimated:YES]; + [weakself setSwipeOffset:0 animated:YES completion:nil]; + }]; + } + } +} + -(void) expandSwipe: (MGSwipeDirection) direction animated: (BOOL) animated { CGFloat s = direction == MGSwipeDirectionLeftToRight ? 1.0 : -1.0;