I have looked at this post : scrollView not scrolling swift
and I see that the accepted answer suggested the person to add bottom constraints to the UIScrollViews subview, contentView. I have the following view hierarchy and constraints on each view:
UIView -> UIScrollView(scrollView) -> UIView(contentView)
//in the View Controller
self.view.addSubview(coverImage)
scrollView.addSubview(contentView)
view.addSubview(scrollView)
here are the NSLayoutConstraints I add to scrollView and contentView
let tmpViewsDictionary = ["scrollView":self.scrollView, "contentView": self.contentView]
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[scrollView]-0-|",options: [], metrics: nil,views: tmpViewsDictionary))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[scrollView]-0-|",options: [], metrics: nil, views: tmpViewsDictionary))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[contentView]-0-|", options: [], metrics: nil, views: tmpViewsDictionary))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[contentView]-0-|", options: [], metrics: nil, views: tmpViewsDictionary))
self.view.addConstraints([NSLayoutConstraint(item :self.contentView, attribute: .Width, relatedBy: .Equal, toItem: self.view, attribute: .Width , multiplier: 1, constant: 0)])
I am following the general structure of this tutorial, which fixes the width and has flexible height of the scrollView.
http://nscookbook.com/2015/06/ios-programming-recipe-36-a-fixed-width-dynamic-height-scrollview-in-autolayout/
When I add content which exceeds the actual parent view Size, I can't scroll down to see the rest of it.
It seems that how they make the height dynamic and the width fixed is to simply constraint the child view of UIScrollView to have an equal width as the parent of UIScrollView. This I do successfully, but the scrolling is still not happening. Thank you for your help!
Here is the full ViewController for this view:
https://gist.github.com/ebbnormal/90c35c435320e0ec1307e95f575119bf
UPDATE
I used Daniels great advice of removing anchoring the bottom of contentView to the scrollView bottom.
So after debugging the view hierarchy, I see that contentView is being set to less than its parent view height, and this seems to stem from an Auto Layout constraint setting the self.bottom of contentView to label.bottom of a UILabel which is a child of contentView. I never set this constraint and I don't know how to get rid of it.
Here is what that looks like in the ViewHierarchy, where the highlighted View is the contentView which you see is cut off.

The way you are adding constraints is most likely the cause of your problem.
It appears that you are constraining the bounds of the content view to be the same as the scroll view. In this case, no scrolling can occur due to the constraints.
This is due to your including self.scrollView and self.contentView within tmpViewsDictionary.
In the tutorial that you linked, the dictionary is only being used for adding constraints to the views that are in the content view of the scroll view. It does not include the scroll view or the content view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With