i have a scrollView. i want it to scroll only in one direction(VERTICAL). Is there a way in which i can lock the horizontal scrolling...?? ...
Since horizontal scrolling is generally a bad idea, this rule can come in handy. To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML. CSS.
Hold Shift & scroll mouse wheel.
Same (adapted) answer for you as in:
Disabling vertical scrolling in UIScrollView
right, all answers here are ok...
but if for some strange reason your contentSize should be higher than the UIScrollView
in both dimensions, you can disable the horizontal scrolling implementing the UIScrollView
protocol method -(void)scrollViewDidScroll:(UIScrollView *)aScrollView
just add this in your UIViewController
float oldX; // here or better in .h interface - (void)scrollViewDidScroll:(UIScrollView *)aScrollView { [aScrollView setContentOffset: CGPointMake(oldX, aScrollView.contentOffset.y)]; // or if you are sure you wanna it always on left: // [aScrollView setContentOffset: CGPointMake(0, aScrollView.contentOffset.y)]; }
it's just the method called when the user scroll your UIScrollView
, and doing so you force the content of it to have always the same .x
self.scrollview.contentSize = CGSizeMake(1, self.scrollview.frame.size.height * number_of_items);
should help. I just locked my scroll view horizontally, by doing the similar technique.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With