Dimitre Bogdanov
Dimitre Bogdanov

Reputation: 396

Placing views and elements within Scroll View

So I'm trying to get a layout to work using Scroll View.

Correct me if I'm wrong but from what I've been reading around the internet, it looks like to properly use Scroll Views and make it work with AutoLayout you need to have your root view, then put the scroll view inside it with constraints binding it to take the whole size of the root view (left/right/top/bottom constraints to 0) and then adding a view inside the scroll view and once again binding it to take up the whole space.

Afterwards, any ui elements or subviews would go in the innermost view.

My problem is that often I have experienced issues while settings my constraints within the scroll view where for example setting a trailing constraint to 0 wouldn't actually set to the end and so on, the numbers just wouldn't add up. In this case when I'm trying to make the innermost view take the whole space,it ends up messing it up more than anything; see image below.

Storyboard Hierarchy

Any help would be appreciated.

Upvotes: 3

Views: 892

Answers (1)

JTango18
JTango18

Reputation: 634

I just created this layout using the follow:

View of layout

To test it, I added an image view to the content view and put a humongous image in it. It scrolls around quite nicely including bounce etc.

Update: You need to select your ViewController and uptick "Adjust Scroll View Insets"

Hope this helps.

Upvotes: 2

Related Questions