swift xib中使用uiscrollview
2020-03-19 本文已影响0人
喵喵粉
步骤
-
view
上拖放scrollview
,设置scrollview
的上下左右4
个约束 -
scrollview
上添加view(vBg)
,做为contentview
,设置vBg
的上下左右4
个约束,
要点
:vBg
的约束不使用Frame Layout Guide
而使用superView即scrollview
来约束
- 垂直方向滚动:定宽度,设置
vBg
的宽度约束:==scrollview
的宽度 - 水平方向滚动:定高度,设置
vBg
的高度约束:==scrollview
的高度
- 添加子
view
,设置其约束
小技巧:先临时设置view
的高度,等子view
的约束拉完就可以删掉

- 约束从
Frame Layout Guide
改到scrollview

或者可以选中scrollview
,去掉content layout guides

- 垂直方向滚动:定宽度
按ctl
拖线

设置vBg
和scrollview
的宽度约束

- 水平方向滚动:定高度
按ctl
拖线


- 横向滚动效果.gif

- 垂直滚动效果图.gif

- 更新:
遇到报错Content and frame layout guides before iOS 11.0
:选中scrollview
,取消勾选Content Layout Guides
