参考链接:https://developer.apple.com/library/ios/technotes/tn2154/_index.html
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/AutoLayoutConcepts/AutoLayoutConcepts.html#//apple_ref/doc/uid/TP40010853-CH14-SW1
先举个例子
要做个这样的
在storyboard中先拖出scrollview imageView label
scrollview的限制
imageView的
label的
通过这个参考view,确定content view的宽度和高度,尽管content view的尺寸可以不依赖于scroll view,但我们还不得不设定content view 和其父view的关系:具体而言就是要确定content view和scroll view的top, bottom, leading和trailing contstraints,这个地方可能比较具有迷惑性,原因是苹果对于这四个约束的使用在scroll view中做了变化:它不再是确定content view尺寸的依据,而是帮助scroll view中content view四周的边界(or你可以理解为留白),进而确定scroll view的contentSize属性。
做scrollView的constraint大家都遇到过下面这个问题吧 来看看要怎么解决呢
UIScrollview可滚动的区域由系统根据scrollView的子view来自动计算的。只有scrollview的contentView的上下左右都和scrollview有关系才能确定scrollview的contentSize(width, height)
原来是底部没有和scrollview保持一定的距离 所以没法确定contentsize的height
在增加一条底部的限制
这样就好了