Search code examples
iosscrollpaginationuiscrollviewbounce

UIScrollView : only paging horizontally left, bouncing right


How can I force a UIScrollView in which paging and scrolling are on to only move horizontally left or horizontally both direction(left and right)?

To be clearer, I'd like to allow the user to 'page only horizontally backward(only bounce when the user try to scroll horizontally right)' OR 'horizontally both direction(this is normal action)' at a given moment.

I am wondering that the solution is the subclass of UIScrollView.

Thanks in advance.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

if ( only bounce.. ){

    // is it right?

    if (scrollView.contentOffset.y > 60) {
        [scrollView setContentOffset:CGPointMake(0, 60)];
    }
}

if ( only paing left... ){

          How to do this??
}

}


Solution

  • I'd implement the delegate function scrollViewDidScroll: and store the state (scroll state) of the ScrollView. On subsequent calls, compare with the previous state and have it bounce back (by calling ZoomToRect: maybe) if it is in a particular direction that you don't like.