gpt4 book ai didi

ios - 使用自动布局删除 View 时重新排列 View

转载 作者:行者123 更新时间:2023-11-28 05:31:01 25 4
gpt4 key购买 nike

我有一个像这样的 UITableViewCell

enter image description here

所有必需的约束都已正确设置,当 iOS 8 中的内容发生变化时,单元格也会自行调整大小。

enter image description here

我必须在某些情况下隐藏标签 3。发生这种情况时,我需要重新定位 label 2 并像这样靠近按钮。

enter image description here

我尝试从标签 2 到按钮添加一个额外的垂直间距约束,并将其关系设置为小于或等于。

enter image description here

cellForRowAtIndexPath 方法中,我删除了标签 3 并更新了布局。

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(InfoCell.identifier(), forIndexPath: indexPath) as InfoCell

cell.label3.removeFromSuperview()
cell.layoutIfNeeded()

return cell
}

enter image description here

但如您所见,标签 2 和按钮之间的间距仍然存在。

我是否需要设置更多约束或更改现有约束的任何设置才能使其正常工作?

最佳答案

尝试将“小于或等于”约束设置为普通约束,将其值设置为您希望在按钮和标签 2 之间保持的距离,并通过将其设置为优先级低于 1000。

通过将其设置为非必需约束,当包含标签 3 时,您将不会遇到无法满足的约束冲突,而当您删除标签 3 时,“非必需但高优先级”约束将生效。

关于ios - 使用自动布局删除 View 时重新排列 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28451308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com