开发者

How to setup vertical only scrolling programmatically

开发者 https://www.devze.com 2023-01-28 00:41 出处:网络
On interface builder there is an option to limit a UIScrollView\'s scrolling to either vertical or horizontal.

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

精彩评论

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

关注公众号