Search code examples
uiscrollview

UIScrollView disable scrolling in just one direction?


I've been unable to find an answer for this (maybe someone has hacked a solution together).

Is it possible to disable scrolling in a UIScrollView in one direction? I am not talking about disabling vertical or horizontal scrolling, but one direction only. So for example, in a UIScrollView, I want to be able to drag the scrollview in a downwards direction, but not in an upwards direction

Thanks


Solution

  • Turns out a simple solution was actually possible and easy:

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        if (scrollView.contentOffset.y > 60) {
            [scrollView setContentOffset:CGPointMake(0, 60)];
        }
    }