Ste*_*ean 3 uitableview ios autolayout swift
我正在使用UITableViewController,我正在加载自定义UITableViewCell.单元中的所有元素和约束都以编程方式配置.TableView看起来像这样
除删除单元格外,所有操作都很完美.我将tableView配置为在删除时淡出单元格.然而,单元格给出一个小的混蛋移动然后它向左而不是褪色,我在控制台中得到自动布局错误消息:"无法同时满足约束"下面
"<NSLayoutConstraint:0x600002551a40 UIView:0x7fccbd5286f0.height == 100 (active)>",
"<NSLayoutConstraint:0x6000025505a0 V:|-(16)-[UIView:0x7fccbd5286f0] (active, names: '|':UITableViewCellContentView:0x7fccbd541b10 )>",
"<NSLayoutConstraint:0x600002550730 UIView:0x7fccbd5286f0.bottom == UITableViewCellContentView:0x7fccbd541b10.bottom (active)>",
"<NSLayoutConstraint:0x6000025605a0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fccbd541b10.height == 1.19209e-07 (active)>"
Run Code Online (Sandbox Code Playgroud)
以下
"<NSLayoutConstraint:0x6000025505a0 V:|-(16)-[UIView:0x7fccbd5286f0] (active, names: '|':UITableViewCellContentView:0x7fccbd541b10 )>",
"<NSLayoutConstraint:0x600002550730 UIView:0x7fccbd5286f0.bottom == UITableViewCellContentView:0x7fccbd541b10.bottom (active)>",
"<NSLayoutConstraint:0x6000025605a0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fccbd541b10.height == 1.19209e-07 (active)>"
Run Code Online (Sandbox Code Playgroud)
并且"将试图通过打破约束来恢复"以下
<NSLayoutConstraint:0x600002551a40 UIView:0x7fccbd5286f0.height == 100 (active)>
<NSLayoutConstraint:0x600002550730 UIView:0x7fccbd5286f0.bottom == UITableViewCellContentView:0x7fccbd541b10.bottom (active)>
Run Code Online (Sandbox Code Playgroud)
我将控制台输出分成几部分,因为我无法将它们全部粘贴在一起.
基本上,我在单元格内部有一个UIView叫cellView(白色圆角区域)contentView.你看到的所有其他元素都在里面cellView.我在cellView和之间应用了以下约束contentView
cellView.translatesAutoresizingMaskIntoConstraints = false
cellView.heightAnchor.constraint(equalToConstant: 100).isActive = true
cellView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 16.0).isActive = true
cellView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true
cellView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16.0).isActive = true
cellView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16.0).isActive = true
Run Code Online (Sandbox Code Playgroud)
当我在删除单元格之前尝试停用单元格及其子视图中的所有约束时,它起了作用.但是,当重新使用新单元时,它们没有激活约束.
我该如何处理这个案子?
Sh_*_*han 11
您需要降低底部约束的优先级
let con = cellView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
con.priority = UILayoutPriority(999)
con.isActive = true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1152 次 |
| 最近记录: |