Permalink
Browse files

Handle drag-to-scroll in horizontal mode.

  • Loading branch information...
1 parent f48bbce commit 115d9956ab653b56b24158665a0e176e3f75e4e8 @bjhomer committed Dec 17, 2010
Showing with 19 additions and 4 deletions.
  1. +19 −4 Classes/HSSidebarView.m
View
23 Classes/HSSidebarView.m
@@ -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
@@ -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
@@ -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) {
@@ -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;
@@ -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;
}
@@ -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

0 comments on commit 115d995

Please sign in to comment.