scb998
scb998

Reputation: 909

UIScrollView and Autolayout

i have the following Storyboard as shown:

storyboard overview

i am trying to get my UIScrollview to scroll. I had it working perfectly without Auto Layout, but it doesn't appear to be working now I've turned Auto Layout on.

I've been following this blog post: How to make a ScrollView with AutoLayout in Xcode5

but the scroll still refuses to work, and i get warnings in relation to ambiguous scroll position (see image below)

enter image description here

can somebody please explain how to set up UIScrollView with auto layout, including the properties of the embedded views (lengths etc)

Upvotes: 1

Views: 351

Answers (1)

Sergey Demchenko
Sergey Demchenko

Reputation: 2954

When you use autolayout with scroll view, you have to follow these rules:

1 Make sure your scroll view frame can be calculated:

1.1 You have to setup leading, top, trailing, bottom constrains of it to parent view.

1.2 Or you can setup x, y position of it (leading and top constraints for example) and width and height constrains.

2 View (or views) frame inside scroll view also should be possible to calculate:

2.1 Make sure that view inside scroll view has leading, top, trailing and bottom constraints and width and height constrains.

2.2 If your view's frame size should be calculated with frames of items in this view, you need:

2.2.1 For this view (inside scroll) setup leading, top, trailing, bottom constraints to scroll view.

2.2.2 For each item in this view setup explicit frame (leading, top, trailing, bottom, width, height constraints).

Upvotes: 1

Related Questions