相對(duì)于普通的View來說, UIScrollView 的AutoLayout 比較特殊.因?yàn)樗?left/right/top/bottom space 是相對(duì)于 UIScrollView的 contentSize 而不是 bounds 來確定的.如果你嘗試用 UIScrollView和它 subview 的left/right/top/bottom 來互相決定大小的時(shí)候,系統(tǒng)會(huì)警告你"Has ambiguous scrollable content width/height".
解決方法:
step 1 : 在scrollView和它的subviews之間,先添加一個(gè) containView,對(duì)齊scrollview的top & leading邊界, scrollView的width &height 對(duì)齊containView,從而使scrollView 的 contentSize確定下來. (contentSize的大小等于containView.size)

step 2:保存下面的NSLayoutConstraint,如果scrollView的寬度變化(如:網(wǎng)絡(luò)請(qǐng)求回來的內(nèi)容增加了),則需要更新此約束.

step3: 添加scrollView 和它的superView 約束

(self.view)
"Talk is cheap? "
使用storyboard來實(shí)現(xiàn)的例子,有好多在網(wǎng)上了.請(qǐng)自行g(shù)oogle.
OK, 我們不使用storyboard, 用純代碼實(shí)現(xiàn)它
例子代碼:https://github.com/dgutyanghs/UIScrollView-AutoLayout-NotUse-Storyboard
I hope this example will help you, enjoy it!