View ios 8 Xcode not Scrolling - Swift

I am very new to Swift and developing on ios, but I cannot find a way to get the UIScrollView to scroll down and stay in place. I have tried tons of tutorials on this and nothing so far. I have a ContentView inside my ScrollView. This ContentView has all my boxes that I want to scroll, but it doesn't scroll. It does bounce though, if it matters ... can anyone send me in the right direction?


source to share

7 replies

Try to install contentSize


override func viewDidLayoutSubviews() {
   scrollView.contentSize = CGSize(width: 375, height: 1500)




I finally figured it out after 2 days and it was very simple. All I did was set the scrollView to the screen size, but then set the content view's height to 1500px and get started. Thanks everyone!



It looks like you might not have set contentSize

for your scroll. To do this, if you are not using automatic layout:

scrollView.contentSize = // The size of your content.


If you are using an automatic layout, you need to make sure you have it NSLayoutConstraints

from every edge of your content to every corresponding edge of yours UIScrollView

. This UIScrollView

will automatically size your content .

Hope it helps.



Just wanted to add a note to FreeTheStudentsAnswer in case anyone had a similar problem - I set the scrollView to screen size and then set the content view height to a higher value and only started working when I set that to viewDidAppear instead of viewDidLoad. Not sure if this will help anyone, but it fixed my problem.



In a scrollview, scrolling occurs only if there is enough space for the scroll to scroll the content.

You said the scrollview and its content are the same size. Then it won't scroll. Scrollview.contentSize must be at least half the size of the scroll if you want to scroll.

Tip: Scroll should not be larger than the iPhone screen. The scroll content must be larger than the scrollview. Scrolling allows you to scroll the contents of your content.



SWIFT 4.0 update

@IBOutlet weak var myScrollView: UIScrollView!

  override func viewDidLoad() {

    myScrollView.alwaysBounceVertical = true
    myScrollView.alwaysBounceHorizontal = true
    myScrollView.isScrollEnabled = true
    myScrollView.contentSize = CGSize(width: 375, height: 1000)




try it

1.scrollView.bounds = YES;
2.scrollView.contentSize = CGSize(width: self.view.frame.size.width, height: YourContentView.frame.size.height);




All Articles