4
votes

Ok so I searched the whole web for a solution to my very specific problem, but couldn't figure it out.

I'm developing a reader app in swift targeting iOS 8.1 and my detailviewcontroller (controller supposed to show the article) has the following setup in place:

-UIView
--UIScrollView
---UIView (contentView)
----UIScrollView(horizontal only)
----TextView
----SegmentedControl
----ContainerView (wired up with a UIPageViewController)

The PageViewController has currently 2 controller as subviews in order to display either the article or comments (both: dynamic height labels for the article content / tableviewcells for the comments). Prior to my approach with UIPageViewController I used a UIView as a custom container (direct subview of contentview) and a tableview (also direct child of contentview) which I toggled to hide/show if a certain segmentindex was selected. Now I want to use a better approach where swiping between the two "tabs" is possible. So I designed the subviews in separate controllers which are being managed by the pageviewcontroller.

The problem: My UIScrollView doesn't show the article/comments in full height. The UIScrollView lays out its subviews and later the viewcontroller contained in the pageviewcontroller is fetching data and populating the textviews to show it. I try to pursue a Pure AutoLayout Approach as described by Apple here. So I set up all necessary constraints from the content view to the scrollview and from the scrollview to its super view. Since the Scrollview can't calculate its content size properly (all it does know is that there're a couple subviews and a container view) I also added a height constraint for the content view which I tried to replace during runtime. So I tried a couple approches listed on SO like these:

iOS: Best way to make a UIScrollView with dynamic height?

How I auto size a UIScrollView to fit the content

And other tutorials like:

http://spin.atomicobject.com/2014/03/05/uiscrollview-autolayout-ios/

but couldn't get it working. Either nothing is shown (if only a placeholder height contraint is in place) or it doesn't scroll since the height is fixed by the contraint. E.g., if I set the contentView's height constraint during runtime to let's say 1000, it works but of course it's not dynamic and thus it's not what I want. I want the ScrollView to scale as its subviews grow/shrink while changing the "tabs".

I can provide code if necessary or build a sample project to exhibit the problem. I've never had any problems with AutoLayout or UIScrollView so far, but this time I've no clue how to get things done.

I hope I stated everything clearly and someone can help. Thanks!

1

1 Answers

-2
votes

Please check out my repo https://github.com/ngominhtrint/ParallaxHeader. I've used XLPagerTabStrip for paging view controllers. Hope it's useful.

enter image description here