1. 准备contentView
必备四行代码 ,配置contentView,以后所有的view都加入到contenview 而不是view
let contentView = UIView() // 必备
let scrollView = UIScrollView()
view.addSubview(scrollView)
scrollView.addSubview(contentView)
2.给Scrollview contentView 设置约束
scrollView.snp.makeConstraints { make in
make.top.equalTo(navBar.bottomLine)
make.left.right.equalTo(view)
make.bottom.equalTo(view).offset(-kBottomMargin)
}
contentView.snp.makeConstraints { make in
make.edges.equalTo(scrollView)
make.width.equalTo(scrollView)
// make.bottom.equalTo(bottomCollectionView.snp.bottom).offset(30)
}
3.在整个布局中的最后一个View自动约束完成后,增加contentView 的bottom 布局约束
contentView.snp.makeConstraints { make in
make.bottom.equalTo(bottomCollectionView.snp.bottom).offset(10)
}