Monday, 29 October 2018

Nested UIScrollviews behaving strangely

I have the following autolayout-driven setup:

One main viewController, with a scrollview inside it. Scrollview pinned to superview edges. This one scrolls up and down.

A few normal, fixed size views at the top of the scrollview, and then another scrollview. This one scrolls left and right.

The second scrollview contains a couple of tableviews, side by side. The idea is that the user can switch between them. They both contain a handful of cells, all the same width as the screen and 72pts tall.

The problem I'm trying to solve is that the tableview contents are not the same size. The left one has say, 6 cells, and the right one has 3.

My first approach was to dynamically change the second scrollview height to match which ever tableview was currently visible. What ended up happening was that switching between the two tableviews (by doing setContentOffset:animated:) went extremely wrong if animated was set to true - it would adjust the content offset so everything was offscreen. In fact it would set the content offset to and then as I switched, about a dozen times, then it'd reset. It was weird, I gave up.

Now I'm trying to just adjust the content inset of the main scrollview to offset the gap in the content of the current tableview, and it's also being weird. When I set the bottom content inset in viewDidLoad, it works fine. When I set it at the time the tableview becomes current, it does nothing.

What gives? What scenarios would lead to these view interactions not behaving properly?



from Nested UIScrollviews behaving strangely

No comments:

Post a Comment