Skip to content

Commit

Permalink
Handle drag-to-scroll in horizontal mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjhomer committed Dec 17, 2010
1 parent f48bbce commit 115d995
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Classes/HSSidebarView.m
Expand Up @@ -443,8 +443,8 @@ - (void)pressedSidebar:(UILongPressGestureRecognizer *)recognizer {
[imageViews insertObject:viewBeingDragged atIndex:newIndex];
[self setNeedsLayout];


if (CGRectGetMaxY(_scrollView.bounds) - hitPoint.y < 50) {
if ((isHorizontal && CGRectGetMaxX(_scrollView.bounds) - hitPoint.x < 50) ||
(!isHorizontal && CGRectGetMaxY(_scrollView.bounds) - hitPoint.y < 50)) {
if (dragScrollTimer == nil) {
self.dragScrollTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self
Expand All @@ -453,7 +453,8 @@ - (void)pressedSidebar:(UILongPressGestureRecognizer *)recognizer {
repeats:YES];
}
}
else if (hitPoint.y - CGRectGetMinY(_scrollView.bounds) < 50) {
else if ((isHorizontal && hitPoint.x - CGRectGetMinX(_scrollView.bounds) < 50) ||
(!isHorizontal && hitPoint.y - CGRectGetMinY(_scrollView.bounds) < 50)) {
if (dragScrollTimer == nil) {
self.dragScrollTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self
Expand Down Expand Up @@ -499,7 +500,7 @@ - (void)pressedSidebar:(UILongPressGestureRecognizer *)recognizer {
delay:0
options:UIViewAnimationCurveEaseOut
animations:^{
viewBeingDragged.transform = CGAffineTransformMakeScale(4.0, 4.0);
viewBeingDragged.transform = CGAffineTransformMakeScale(0.8, 0.8);
viewBeingDragged.alpha = 0.0;
}
completion:^(BOOL finished) {
Expand Down Expand Up @@ -529,6 +530,11 @@ - (void)scrollWithDelta:(CGFloat)scrollDelta duration:(NSTimeInterval)duration {
CGFloat contentBottom = _scrollView.contentSize.height;
CGFloat scrollBottom = CGRectGetMaxY(_scrollView.bounds);

if (isHorizontal) {
contentBottom = _scrollView.contentSize.width;
scrollBottom = CGRectGetMaxX(_scrollView.bounds);
}

CGFloat availableContentSpace = contentBottom - scrollBottom;
if (availableContentSpace <= 0) {
scrollDelta = 0;
Expand All @@ -540,6 +546,10 @@ - (void)scrollWithDelta:(CGFloat)scrollDelta duration:(NSTimeInterval)duration {
else {
// Scrolling up; make sure we don't go beyond the top.
CGFloat contentTop = _scrollView.contentOffset.y;
if (isHorizontal) {
contentTop = _scrollView.contentOffset.x;
}

if (contentTop < (-1 * scrollDelta)) {
scrollDelta = -1 * contentTop;
}
Expand All @@ -551,6 +561,11 @@ - (void)scrollWithDelta:(CGFloat)scrollDelta duration:(NSTimeInterval)duration {
CGPoint newOffset = CGPointMake(0, currentContentOffset.y + scrollDelta);
CGPoint newViewCenter = CGPointMake(viewBeingDragged.center.x, viewBeingDragged.center.y + scrollDelta);

if (isHorizontal) {
newOffset = CGPointMake(currentContentOffset.x + scrollDelta, 0);
newViewCenter = CGPointMake(viewBeingDragged.center.x + scrollDelta, viewBeingDragged.center.y);
}

[UIView animateWithDuration:duration
delay:0
options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveLinear
Expand Down

0 comments on commit 115d995

Please sign in to comment.