【发布时间】:2023-03-13 22:34:01
【问题描述】:
有人知道将所有子视图的 translatesAutoresizingMaskIntoConstraints 设置为 false 的含义吗?
考虑以下几点:
extension UIView {
public func setAutoresizingMaskIntoConstraintsForAllSubviews() {
for v in self.subviews {
v.translatesAutoresizingMaskIntoConstraints = false
}
}
}
...
let cell = UITableViewCell()
cell.setAutoresizingMaskIntoConstraintsForAllSubviews() //or
cell.contentView.setAutoresizingMaskIntoConstraintsForAllSubviews()
根据我的测试,一切正常。我没有看到与任何 UIKit 组件的任何约束冲突。
根据 Apple 的文档:
默认情况下,该属性设置为 true 用于您的任何视图 以编程方式创建。如果在 Interface Builder 中添加视图, 系统自动将此属性设置为false。
https://developer.apple.com/reference/uikit/uiview/1622572-translatesautoresizingmaskintoco
【问题讨论】:
标签: ios swift uitableview uikit constraints