【发布时间】:2019-08-21 22:36:27
【问题描述】:
我在包含三个视图的表格单元格内有堆栈视图。我希望堆栈视图在隐藏一两个视图时自行调整。我的问题与以下问题中的描述完全相同,只是我的堆栈视图位于表格单元格内。这些线程中提到的解决方案对我不起作用。有关确切问题,请参见下面的屏幕截图。
堆栈视图被固定到所有侧面并且分布被平均填充。
我们如何让它发挥作用?
UIStackView shift content to left when inner views are hidden
UIStackView Distribution Fill Equally
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "tableCellID", for: indexPath) as? TableViewCell else {
fatalError("Can't find cell")
}
let profile = array[indexPath.row]
if profile.status {
cell.view2.isHidden = false
} else {
cell.stackViewTrailing.constant += cell.view2.frame.size.width
cell.view2.isHidden = true
}
return cell
}
【问题讨论】:
-
显示您的
TableViewCell课程。使用自动布局实际上非常容易。 -
我已经上传了故事板截图。
-
堆栈视图尾随设置为什么?
-
设置为superview包含它。
-
该视图的锚点是否设置为
contentView的锚点。
标签: ios swift uitableview uistackview