0

I have built an UIScrollView like this:

enter image description here

The main idea is Label content and Label Re has a auto fixed height according to the content size and they are contained by a view.

And there is a share button following that view.

All build correctly except that I can't scrolling the view to the bottom to see the button if the content is large so that the button is out of the main screen. Or I shall try very hard to scroll to see the button and it will scroll back when I let go. :-(

enter image description here

armnotstrong
  • 8,605
  • 16
  • 65
  • 130

4 Answers4

1

After a long search, what works for me is that adding a "Bottom" Constrains to the last view to its superview.

enter image description here

K-Soliman
  • 914
  • 7
  • 11
0

Bottom constraint of button is missing due to which its not resizing and scrollable. To fix this, add bottom constraint to button and keep it as greater than equal to some value. e.g. 20 (whatever bottom spacing you want)

Sneha
  • 34
  • 2
0

What you have done is, you placed a single root view for your scrollView. In this case you need to specify enough height that would be consumed by all the subviews inside the root view. (which may be confusing )

Instead of placing all views under one single view, remove that root view, embed all views under scroll view. i.e

scroll view

    -> view 1

    -> view 2

    -> button

Constraints are as follows:

scrollView -> pin trailing, leading, top and set proper height This would set scroll view position and size

view 1 -> pin top, trailing , leading to superview and pin bottom to its bottom view (view 2). (Specify height, width if necessary)

view 2 -> pin top, leading, trailing to top view (view 1) and pin bottom to button . (Specify height, width if necessary)

button -> pin top, leading, trailing to top view (view 2) and pin bottom to scroll view. (Specify height, width if necessary)

This will set enough constraints for your scroll view to calculate content.

Let me know if this doesn’t work.

cgeek
  • 558
  • 5
  • 18
-1
override func viewDidLoad() {
  super.viewDidLoad()
  automaticallyAdjustsScrollViewInsets = false
}

Give this a shot, if it doesn't work, I'll look closer.

jnblanchard
  • 1,182
  • 12
  • 12