1

How can I disable scrolling left on a UIScrollview. This is so users can only scroll right?

Thanks

*** UPDATE *****

This is what I have now. I have subclassed UIScrollView and overwritten the following methods

@implementation TouchScrollView

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view {
    NSLog(@"touchesShouldBegin: I was touched!");
    return YES;
}

- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
    NSLog(@"touchesShouldCancelInContentView: I was touched!");
    return NO;
}

In my viewController I have also set the following attributes:

scrollView.delaysContentTouches = NO;
scrollView.canCancelContentTouches = YES;

TouchesShouldBegin is being called but touchesShouldCancelInContentView is not being called and I cant figure out why!!

Thanks

user609906
  • 190
  • 3
  • 6
  • 12
  • i have the same issue.did u find out why canCancelContentTouches never gets called even id canCancelContentTouches is set to YES? – prostock May 13 '11 at 20:37

2 Answers2

1

just add this in your UIViewController UIScrollViewDelegate

float oldX; // here or better in .h interface

- (void)scrollViewDidScroll:(UIScrollView *)aScrollView
{
    if (scrollView.contentOffset.x < oldX) {
        [aScrollView setContentOffset: CGPointMake(oldX, aScrollView.contentOffset.y)];
    } else {
        oldX = aScrollView.contentOffset.x;
    }

}
meronix
  • 6,175
  • 1
  • 23
  • 36
  • not working on the Ipad. If you scroll quickly it will scroll on the left direction then after do [aScrollView setContentOffset: CGPointMake(oldX, aScrollView.contentOffset.y)]; – ludo Oct 17 '11 at 04:28
0

You should handle swipe gestures.

Check similar question here: iOS Advanced Gestures: Getting Swipe Direction Vector

Community
  • 1
  • 1
knuku
  • 6,082
  • 1
  • 35
  • 43