我有一个应用程序
我尝试如下所示对其进行约束,但我缺少一个约束,而且我找不到我需要的东西。
self.view.addSubview(self.scrollView)
self.scrollView.snp.makeConstraints { (make) in
make.edges.equalTo(self.view)
}
let contentView = UIView()
self.scrollView.addSubview(contentView)
contentView.snp.makeConstraints { (make) in
make.top.bottom.equalTo(self.scrollView)
make.left.right.equalTo(self.view)
}
contentView.addSubview(self.chart)
self.chart.snp.makeConstraints { (make) in
// http://snapkit.io/docs/
make.edges.equalTo(contentView).inset(UIEdgeInsets(top: 30, left: 0, bottom: 50, right: 0))
}
哪里
scrollView = UIScrollView()
最佳答案
您需要为 contentView 添加宽度/高度或对齐约束。尝试这个:
contentView.snp.makeConstraints { (make) in
make.top.bottom.equalTo(self.scrollView)
make.left.right.equalTo(self.view)
make.width.equalTo(self.scrollView)
make.height.equalTo(self.scrollView)
// or:
// make.centerX.equalTo(self.scrollView)
// make.centerY.equalTo(self.scrollView)
}
关于swift - 在 UIScrollView 中使用 snapkit/autolayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52855503/