On interface builder there is an option to limit a UIScrollView's scrolling to either vertical or horizontal.
However I couldn't find a property or a method in UIScrollVi开发者_Go百科ew to enable such behavior.
Is it achieved through some other way or am I missing something?
In addition to setting the contentSize
width as mentioned, you should also set the scrollView.alwaysBounceHorizontal = NO
to stop the horizontal bounce which will still be on.
The solution is from the question already answered:
UIScrollView *scrollView;
CGRect size = scrollView.contentSize;
size.width = CGRectGetWidth(scrollView.frame);
scrollView.contentSize = size;
scrollView.alwaysBounceHorizontal = NO;
Set your contentSize
property such that its width is the same as your scrollview's width. Tada! No more horizontal scrolling.
I don't think that limits scrolling in those directions, it just determines whether the scroll indicators are shown (so the properties would be showsHorizontalScrollIndicator and showsVerticalScrollIndicator).
精彩评论