I know that a scroll view can determine it's contentSize based on the way its subviews are constrained. I have a slightly more tricky situation that I would like to resolve using auto layout.
I am using a paging scroll view, similar to that in the weather app. But I am lazily loading each page of content when it is required. Previously I simply set the contentSize width of the scrollview to x * the scrollview's width, where x is the number of pages of content. Then the origin of each page is offset depending on the page number.
With autolayout I need to add a page of content and pin it to an edge of the scrollview, so that it can determine the correct content size. If I am loading page 3 of 6, the trailing space to the edge of the scrollview would be 3 X the scrollview width. A similar leading constraint can be determined.
Visually, it is similar to the following (pseudocode):
|-(scrollView.width*pageNumber)-[page]-(scrollview.width * (pages.count - pageNumber))-|
Thus placing the page in correct location, with sufficient left and right margins so that the scrollview knows its content size.
What is the correct way to add such a constraint, such that:
- no magic numbers are used
- the layout will work on rotation
I have tried multiple approached but can't quite get it.