开发者

How to setup vertical only scrolling programmatically

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?

How to setup vertical only scrolling programmatically


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜