【发布时间】:2020-01-23 08:31:31
【问题描述】:
我正在尝试使这种布局以某种方式动态化。这里的选项是动态的(数量未知),所以我们可以轻松地将这些选项放在 tableView、collectionView 或只是简单的 scrollView 中。
问题是我想让这个白色容器尽可能小并垂直居中。当我将 centerY 约束与 Top+Bottom 插入结合时,似乎只有顶部和底部约束被激活。
And when the options are quite long, options can be scrollable, BUT maintaining the fact that there are top and bottom insets.
我心里已经有了一些想法,比如观察容器视图的高度是否超过设备高度。
我使用 snapKit,但限制应该是可以理解的。这是我目前的布局:
func setupUI() {
self.view.backgroundColor = .clear
self.view.addSubviews(
self.view_BGFilter,
self.view_Container
)
self.view_BGFilter.snp.makeConstraints {
$0.edges.equalToSuperview()
}
self.view_Container.snp.makeConstraints {
$0.centerY.equalToSuperview().priority(.high)
//$0.top.bottom.greaterThanOrEqualToSuperview().inset(80.0).priority(.medium)
$0.leading.trailing.equalToSuperview().inset(16.0)
}
// Setup container
self.view_Container.addSubviews(
self.label_Title,
self.stackView,
self.button_Submit
)
self.label_Title.snp.makeConstraints {
$0.top.equalToSuperview().inset(40.0)
$0.leading.trailing.equalToSuperview().inset(16.0)
}
self.stackView.snp.makeConstraints {
$0.top.equalTo(self.label_Title.snp.bottom).offset(29.0)
$0.leading.trailing.equalToSuperview().inset(24.0)
}
self.button_Submit.snp.makeConstraints {
$0.height.equalTo(52.0)
$0.top.equalTo(self.stackView.snp.bottom).offset(30.0)
$0.bottom.leading.trailing.equalToSuperview().inset(24.0)
}
self.generateButtons()
}
【问题讨论】:
-
您是否希望选项按钮** 滚动(在需要时),将标题和确定按钮留在原处?还是您希望标题、选项按钮和 OKAAAAY 按钮全部滚动?
标签: ios constraints nslayoutconstraint snapkit