Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a possibility to disable/enable swipe actions of the cell #275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions SWTableViewCell/PodFiles/SWCellScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@

@interface SWCellScrollView : UIScrollView <UIGestureRecognizerDelegate>

@property (assign, nonatomic) BOOL panDisabled;

@end
3 changes: 3 additions & 0 deletions SWTableViewCell/PodFiles/SWCellScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ @implementation SWCellScrollView
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer == self.panGestureRecognizer) {
if (self.panDisabled) {
return NO;
}
CGPoint translation = [(UIPanGestureRecognizer*)gestureRecognizer translationInView:gestureRecognizer.view];
return fabs(translation.y) <= fabs(translation.x);
} else {
Expand Down
2 changes: 2 additions & 0 deletions SWTableViewCell/PodFiles/SWTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ typedef NS_ENUM(NSInteger, SWCellState)

@interface SWTableViewCell : UITableViewCell

@property (nonatomic, assign) BOOL swipeEnabled;

@property (nonatomic, copy) NSArray *leftUtilityButtons;
@property (nonatomic, copy) NSArray *rightUtilityButtons;

Expand Down
11 changes: 10 additions & 1 deletion SWTableViewCell/PodFiles/SWTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ @interface SWTableViewCell () <UIScrollViewDelegate, UIGestureRecognizerDelegat
@property (nonatomic, assign) SWCellState cellState; // The state of the cell within the scroll view, can be left, right or middle
@property (nonatomic, assign) CGFloat additionalRightPadding;

@property (nonatomic, strong) UIScrollView *cellScrollView;
@property (nonatomic, strong) SWCellScrollView *cellScrollView;
@property (nonatomic, strong) SWUtilityButtonView *leftUtilityButtonsView, *rightUtilityButtonsView;
@property (nonatomic, strong) UIView *leftUtilityClipView, *rightUtilityClipView;
@property (nonatomic, strong) NSLayoutConstraint *leftUtilityClipConstraint, *rightUtilityClipConstraint;
Expand Down Expand Up @@ -190,6 +190,15 @@ - (void)dealloc
[self removeOldTableViewPanObserver];
}

- (BOOL)swipeEnabled {
BOOL result = !self.cellScrollView.panDisabled;
return result;
}

- (void)setSwipeEnabled:(BOOL)swipeEnabled {
self.cellScrollView.panDisabled = !swipeEnabled;
}

- (void)setContainingTableView:(UITableView *)containingTableView
{
[self removeOldTableViewPanObserver];
Expand Down