I'm creating a application using Swift3, and i have difficult to define correctly height for UIScrollView, i'm using autolayout and create this structure:
UIScrollViewUIView// The containerviewUIImageView//ConstraintTop Edges = 20 in relation toUIViewUITextView//ConstraintTop Edges = 40 in relation toUIImageViewUITextView//ConstraintTop Edges = 20 in relation toUITextViewUIButton//ConstraintTop Edges 30 in relation toUITextView
Currently, i'm using this logic to calculate UIScrollView height
override func viewDidLayoutSubviews() {
var scrollHeight : CGFloat = 0.0
for view in self.containerView.subviews {
view.layoutIfNeeded()
scrollHeight += view.frame.size.height
}
// Adding height for scrollview, according to the sum of all child views
self.scrollView.contentSize.height = scrollHeight
}
But, i can only get the views height, and them not consider the Constraints "margins", i would like know any way to calculate correct height for UIScrollView, adjusted according their content.