scroll view not scrolling vertically

12,226

Solution 1

You're using constraints in your scroll view, so the content size is determined by the constraints, not by setting the contentSize in code. You need to fix your constraints so that they size the content from the inside out of the scroll view. The top subview of the scrollview needs to be pinned to the scrollview's top, and the bottom subview needs to be pinned to the scrollview's bottom, and all the views in between need to be pinned to one another, in such a way as to dictate the desired content size height. But the scroll view itself needs to be pinned to its superview, so that it is not taller than the screen. In other words, this will work when the sum of the constrained heights inside the scroll view is greater than the constrained height of the scroll view.

Solution 2

Problem is in constraints. Follow these steps:

Add a container view in scroll view and set top, bottom, leading and trailing constraints of container view with scroll view. Do not set height of this container view. add other views in this container view. Height of container view will adjusted according to sub views of container view. Height of sub views of container view should not set proportional to container view, it should set proportional to scroll view.

Also make sure you have set the top and bottom of container view to its sub view

Share:
12,226
S.M_Emamian
Author by

S.M_Emamian

I was born in Kashan. I think the technology means Let me try.. Actually I'm have interested in a wide-range of technology topics, including programming languages, opensource and any other cool technology that catches my eye. I'm using Ubuntu 15.10,El capital.

Updated on June 27, 2022

Comments

  • S.M_Emamian
    S.M_Emamian almost 2 years

    I have a scroll view that it not scrolling at all:

    enter image description here


    enter image description here

    enter image description here

        scroll_view_content_a_job.contentSize.height = 1800
        scroll_view_content_a_job.isScrollEnabled = true
    
  • matt
    matt about 7 years
    I should add that most people find this sort of thing a lot easier to configure by putting a "container view" inside the scroll view and everything else inside that.
  • mfaani
    mfaani almost 6 years
    Would this be a correct summary? There are two ways to add views into the scrollView 1. No need to specify contentSize add them directly into the scrollView, | 1--2--3--4--5--| the combined height of 1,2,3,4,5 would implicitly create the height of the contentsize and the maximum width among 1,2,3,4,5 would create the width of the contentSize. This is usually hard to todo. 2. specify the contentSize just dump views into the containerView of the scrollView. A lot easier.
  • alierdogan7
    alierdogan7 about 2 years
    Thanks for warning that none of container's subviews should have proportional height to container, but should have proportional height to scroll view. That solved my problem.