Skip to content

Commit 2f31df0

Browse files
committed
Merge pull request CEWendel#50 from mergesort/scroll_enabled
Replace scrollEnabled = YES and NO by turning on directionLockEnabled on the tableView
2 parents 642f49b + eafaa6a commit 2f31df0

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

SWTableViewCell/PodFiles/SWTableViewCell.m

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ - (void)initializer
137137
{
138138
[self.scrollViewContentView addSubview:subview];
139139
}
140+
141+
self.containingTableView.directionalLockEnabled = YES;
140142
}
141143

142144
- (void)layoutSubviews
@@ -152,7 +154,6 @@ - (void)layoutSubviews
152154
self.scrollViewButtonViewRight.layer.masksToBounds = YES;
153155
self.scrollViewContentView.frame = CGRectMake([self leftUtilityButtonsWidth], 0, CGRectGetWidth(self.bounds), self.height);
154156
self.cellScrollView.scrollEnabled = YES;
155-
self.containingTableView.scrollEnabled = YES;
156157
self.tapGestureRecognizer.enabled = YES;
157158
}
158159

@@ -531,33 +532,36 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi
531532

532533
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
533534
{
534-
self.containingTableView.scrollEnabled = NO;
535535
self.tapGestureRecognizer.enabled = NO;
536536
if (scrollView.contentOffset.x > [self leftUtilityButtonsWidth])
537537
{
538-
CGFloat scrollViewWidth = MIN(scrollView.contentOffset.x - [self leftUtilityButtonsWidth], [self rightUtilityButtonsWidth]);
539-
540-
// Expose the right button view
541-
self.scrollViewButtonViewRight.frame = CGRectMake(scrollView.contentOffset.x + (CGRectGetWidth(self.bounds) - scrollViewWidth), 0.0f, scrollViewWidth,self.height);
542-
543-
CGRect scrollViewBounds = self.scrollViewButtonViewRight.bounds;
544-
scrollViewBounds.origin.x = MAX([self rightUtilityButtonsWidth] - scrollViewWidth, [self rightUtilityButtonsWidth] - scrollView.contentOffset.x);
545-
self.scrollViewButtonViewRight.bounds = scrollViewBounds;
538+
if ([self rightUtilityButtonsWidth] > 0)
539+
{
540+
CGFloat scrollViewWidth = MIN(scrollView.contentOffset.x - [self leftUtilityButtonsWidth], [self rightUtilityButtonsWidth]);
541+
542+
// Expose the right button view
543+
self.scrollViewButtonViewRight.frame = CGRectMake(scrollView.contentOffset.x + (CGRectGetWidth(self.bounds) - scrollViewWidth), 0.0f, scrollViewWidth,self.height);
544+
545+
CGRect scrollViewBounds = self.scrollViewButtonViewRight.bounds;
546+
scrollViewBounds.origin.x = MAX([self rightUtilityButtonsWidth] - scrollViewWidth, [self rightUtilityButtonsWidth] - scrollView.contentOffset.x);
547+
self.scrollViewButtonViewRight.bounds = scrollViewBounds;
548+
}
546549
}
547550
else
548551
{
549-
CGFloat scrollViewWidth = MIN(scrollView.contentOffset.x - [self leftUtilityButtonsWidth], [self leftUtilityButtonsWidth]);
550-
551552
// Expose the left button view
552-
self.scrollViewButtonViewLeft.frame = CGRectMake([self leftUtilityButtonsWidth], 0.0f, scrollViewWidth, self.height);
553-
553+
if ([self leftUtilityButtonsWidth] > 0)
554+
{
555+
CGFloat scrollViewWidth = MIN(scrollView.contentOffset.x - [self leftUtilityButtonsWidth], [self leftUtilityButtonsWidth]);
556+
557+
self.scrollViewButtonViewLeft.frame = CGRectMake([self leftUtilityButtonsWidth], 0.0f, scrollViewWidth, self.height);
558+
}
554559
}
555560
}
556561

557562
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
558563
{
559564
self.tapGestureRecognizer.enabled = YES;
560-
self.containingTableView.scrollEnabled = YES;
561565
}
562566

563567
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
@@ -566,7 +570,6 @@ - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
566570
self.tapGestureRecognizer.enabled = YES;
567571
if (_cellState == kCellStateCenter)
568572
{
569-
self.containingTableView.scrollEnabled = YES;
570573
self.longPressGestureRecognizer.enabled = YES;
571574
}
572575
}

0 commit comments

Comments
 (0)