UIScrollView Content UpdateSize Scrolling Reasons

I have a UIScrollView in which there is one child view. If I set contentSize from a UIScrollView right after creation, everything works as I expect, and I get the scroll.

The challenge is that the view in UIScrollView has a dynamic size. The width is fixed, but the height is unknown during the scroll setting.

When I do [scrollView setContentSize:CGRectMake(...)] after the internal view does this, update the scrollview to the desired size and scroll. Thus, the main scroll works fine.

However, the main problem is that when I setContentSize at a later point, the UIScrollView decides to scroll down (with animation) to the end of the scroll, which is not what I want, I want the scroll to stay at the top, and let the contents in the scroll list be more or less, without changing the visible scroll position.

What am I missing?

+4
source share
2 answers

Why don't you also call [scrollview setContentOffset:CGPointMake(0,0)]; when calling setContentSize?

+6
source

To make UIScrollView scroll only, for example. horizontally, I always set the value without scroll for contentSize to 0 using:

 CGSizeMake(contentSize.width, 0). 
0
source

Source: https://habr.com/ru/post/1338315/


All Articles