This session sums up most of the mysteries of auto layout developers come across.
A powerful UIKit component to build up a complex layout without forgiving the maintainability. UIStackView is also able to nested. Hiding the views inside the stackView will make other subviews taking views room.
//Animation with stackView
UIView.animateWithDuration(1.0) {
self.subviewToHide.hidden = !self.subviewToHide.hidden
}
Prior to iOS 9, for any referenced constraints, we have to remove and re-add the constraints to certain views in order to make these effective or not. In iOS 9, there are activate and deactivate for the constraint to take or not into account when layout engine performs layouting.
Never deactivate self.view.constraints as additional internal constriants added to that view
Use Constraints to define the size of a view
Overriding intrinsicContentSize for
invalidateIntrinsicContentSize so that the layout system notices the change and can recalculate the layout. //calculating width based on superview's width
widthConstraint = NSLayoutConstraint(item: imageView,
attribute: .Width,
relatedBy: .Equal,
toItem: self.view,
attribute: .Width,
multiplier: 0.75,
constant: 0.0)
//Calculating height based on image's width
heightConstraint = NSLayoutConstraint(item: imageView,
attribute: .Height,
relatedBy: .Equal,
toItem: imageView,
attribute: .Width,
multiplier: 1.5,
constant: 0.0)
@"V:|-[image]-[caption](==image@751)]-1" to set the constraints' priorities

firstBaseLine and lastBaseline to align the first and last of line of text of base linesalignmentRectInsets if needed to provide paddingalignmentRectForFrame:Related Session