3

I'm struggling with UIScrollView for a while now.

"descriptionLabel" and "genresLabel" will increase height during runtime and the gap to actors will increase. So i need the scrolling functionality here to see the actors label.

I set the height of the contentView as a height-constraint equal to View with priority 250 and hoped that the height will increase automatically if needed.

In fact nothing happens and no scrolling is possible.

How can i automatically increase the contentView height in the auto-layout context?

Storyboard

5
  • Does your ContentView's height grows as your labels' heights become bigger? Commented May 22, 2015 at 9:59
  • i hope so because the actors label will go down if the others label height increases. so there must be an increase of the contentview's height too... Commented May 22, 2015 at 11:18
  • Please, look at my answer, I've just created test project for you Commented May 22, 2015 at 11:49
  • I already answer to this question here: stackoverflow.com/questions/19036228/… Commented May 22, 2015 at 11:51
  • Maybe you can use an UITableView with two sections and a footer view for the first one. Commented May 22, 2015 at 12:14

5 Answers 5

3

You have to make ContentView's height flexible so it should get increased and the scrollview's content size will increase accordingly. Have a look into attached screenshots. Increase the bottom label top constraint (which is 495) value the scrollview's content size will get increased automatically.

Here is the Sample Source Code

enter image description here

enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

10 Comments

First of all thanks for the screenshot explanation. I removed my height constraint of the ContentView (to View) but it changes nothing. I even get the following error in my storyboard: "Scrollview has ambiguous scrollable content height".
I have uploaded the sample code please download and check speedy.sh/7XVBk/Sample.zip
i added in your project the constraints mentioned in you screenshots. result is identically to my project. Error: "Scrollview has ambiguous scrollable content height" So there must be a hight defined for the contentview?
In this video the contentView height is increased in storyboard during the design process. During my design process all the labels fit on the screen but it is possible that the label height increases dependent on the content. so if i set the height constraint on the contentview, the height is fixed for this view, right?
if your label height will increase then the content height also should get increased(coz its super view of labels) and then the scrollview will scroll.
|
1

Is your Actors label, the last element on this View? If it is then fix both Actors: and asdfas... to top, bottom and left. Now, for bottom set 'Constant' as 'Use standard value'.Also fix topmost element(here maybe 'No network connection!') to top and set its 'Constant' as 'Use standard value'. Try this and let me know if it works!

I have tried what i have told you.Pasting images of the same. Hope it helps! enter image description here

enter image description here

enter image description here For Actors label constraints include:

enter image description here and for asdfas label constrains are as shown in the following image: enter image description here

2 Comments

Yes, actors label ist the last element of the view and the constraints are all set.
Thx, for you help! my mistake was the missing bottom constraint of the last label.
0

Just check this link, just have to write this to add up content view height:-

override func viewDidLayoutSubviews() { let scrollViewBounds = scrollView.bounds let containerViewBounds = contentView.bounds var scrollViewInsets = UIEdgeInsetsZero scrollViewInsets.top = scrollViewBounds.size.height/2.0; scrollViewInsets.top -= contentView.bounds.size.height/2.0; scrollViewInsets.bottom = scrollViewBounds.size.height/2.0 scrollViewInsets.bottom -= contentView.bounds.size.height/2.0; scrollViewInsets.bottom += 1 scrollView.contentInset = scrollViewInsets } 

Comments

0

It's hard to understand whats wrong with your layout, so I've created test project with a 2 growing labels, all works fine, maybe you will find out what's wrong in your constraints :)

https://www.dropbox.com/s/j8269c03b32gra5/scrollview-test.zip?dl=0

Build my project and click "More text" button to add text dynamically to labels in scrollview

2 Comments

Thnx for the testproject. I see that you set the contentview height bigger than the viewcontroller height. In my normal case that shouldn't be the case, only when the labelsize increases dramatically. So there should only be a scrolling if the lables don't fit to the screen size.
thx, for you help! my mistake was the missing bottom constraint of the last label.
0

For me, I needed to add a bottom constraint to my last element in the page. More explained here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.