I'm adding subviews programmatically.
Requirement : when extra views are added the scroll should be enabled.
The constraints that I applied :
To remove extra spaces at the top I wrote self.automaticallyAdjustsScrollViewInsets = false
also give content size as self.scrollView.contentSize = CGSize(width: self.contentView.frame.width, height: self.contentView.frame.height*2)
But the when the view is loaded scroll is completely disabled.
Please help me
When you using auto layout, you have to set content size at viewcontroller method, you have to override following method.
-(void)viewWillLayoutSubviews;
swift
override func viewWillLayoutSubviews() {
}
Try to set contentview height, based on (origin.y + height) of subview at bottom in scroll contentview.
There are few things that you need to do, check that you have this enabled.
- Bounces
- Bounces Vertically
- Scrolling Enabled
If enabling those still doesn't help with the scrolling, add a Height constraint of your ContentView
. You have to connect this constraint as an IBOutlet
to your View Controller.
I believe your data is fetched from server, as such you have an ambiguous content height. So at where you print the contentSize
of value (375.0,1334.0)
in your question, add this line of code and you should be able to scroll thereafter.
YourHeightConstraint.constant = self.scrollView.contentSize.height