Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView + Autolayout + Interface Builder: No scrolling, extra space at top after bounce

I'm attempting to embed several sets of buttons and labels in a scroll view using Interface Builder and autolayout. I've tried nearly every solution I can find but nothing gets the scroll view scrolling (i.e. scrolling enabled + no bounces enabled = no movement). In addition, when I do enable bouncing, attempting to scroll down, while revealing the extra content but bouncing back up, leaves what is likely 20px more space at the top of the scroll view, as the content inset seems to get stuck at -20px in the y.

What I've tried so far:

  • Setting content size, content insets manually. Doesn't and shouldn't work with auto layout.
  • Setting every constraint I can find to make sure the scroll view can tell how big it is. Content size at runtime is still zero. This includes sizing constraints on the scroll view and positioning constraints on the buttons and labels inside.
  • Various combinations of IB settings and metrics.
  • Embedding the buttons and labels inside another UIView, which is inside the scroll view. No change.
  • Read the similar questions and answers here.

I'd like to avoid writing code to do this, as it seems like the tools should be able to do this, but I will if I have to. But I'm at a loss; I haven't seen anything that would fix this that I shouldn't be able to do in IB just as well as code.

like image 599
Jon Shier Avatar asked Jan 02 '14 22:01

Jon Shier


1 Answers

Adding height and width constraints, as well as size 0 spacing constraints between a content view and the scroll view seems to have fixed the scrolling issue, finally. Now if only I could figure out why the contentOffset is being set to 20 by default and when scrolling back to the top.

like image 175
Jon Shier Avatar answered Oct 06 '22 16:10

Jon Shier