Ios 为什么Xcode控制台打印约束模糊警告,而UI调试器不打印';T
我有一个自定义UITableViewCell,它看起来像这样,并不复杂: 制约因素包括:Ios 为什么Xcode控制台打印约束模糊警告,而UI调试器不打印';T,ios,swift,uitableview,Ios,Swift,Uitableview,我有一个自定义UITableViewCell,它看起来像这样,并不复杂: 制约因素包括: 水平方向上,所有间距均为16 在垂直方向上,所有间距均为16:male.top=16,male.bottom=16,female.centerY=male.centerY,other.centerY=female.centerY 按钮的宽度相等:阴性。宽度=阳性。宽度,其他。宽度=阴性。宽度 按钮的高度等于35,男性。高度=35,女性。高度=男性。高度,其他。高度=女性。高度 代码为: for butto
for button in [maleButton, femaleButton, otherButton] {
button.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(button)
}
var constraints: [NSLayoutConstraint] = []
constraints += NSLayoutConstraint.constraints(
withVisualFormat: "H:|-16-[male]-16-[female]-16-[other]-16-|",
options: [],
metrics: nil,
views: ["male": maleButton, "female": femaleButton, "other": otherButton]
)
constraints += NSLayoutConstraint.constraints(
withVisualFormat: "V:|-16-[male(35)]-16-|",
options: [],
metrics: nil,
views: ["male": maleButton]
)
constraints.append(
NSLayoutConstraint.init(
item: femaleButton,
attribute: .height,
relatedBy: .equal,
toItem: maleButton,
attribute: .height,
multiplier: 1,
constant: 0
)
)
constraints.append(
NSLayoutConstraint.init(
item: femaleButton,
attribute: .width,
relatedBy: .equal,
toItem: maleButton,
attribute: .width,
multiplier: 1,
constant: 0
)
)
constraints.append(
NSLayoutConstraint.init(
item: femaleButton,
attribute: .centerY,
relatedBy: .equal,
toItem: maleButton,
attribute: .centerY,
multiplier: 1,
constant: 0
)
)
constraints.append(
NSLayoutConstraint.init(
item: otherButton,
attribute: .height,
relatedBy: .equal,
toItem: femaleButton,
attribute: .height,
multiplier: 1,
constant: 0
)
)
constraints.append(
NSLayoutConstraint.init(
item: otherButton,
attribute: .width,
relatedBy: .equal,
toItem: femaleButton,
attribute: .width,
multiplier: 1,
constant: 0
)
)
constraints.append(
NSLayoutConstraint.init(
item: otherButton,
attribute: .centerY,
relatedBy: .equal,
toItem: femaleButton,
attribute: .centerY,
multiplier: 1,
constant: 0
)
)
NSLayoutConstraint.activate(constraints)
控制台中的警告消息是:
但是,当我尝试使用UI调试器时,没有发出运行时约束模糊警告,为什么?我应该担心控制台中的这个警告消息吗?Xcode在谈到约束中的问题时并不十分清楚。经验法则是,每个项目都必须以某种方式声明其高度、宽度、在x轴上的位置和在y轴上的位置。我注意到在你的描述中,你已经指定了水平间距,但你没有说它们应该在窗口的中心,或者在一边,或者其他任何地方。@HackSaw他提到了一个按钮的垂直间距。这应该足够了。我的问题是-这些约束是相对于表视图单元格的
contentView
设置的吗?另外,为什么不为此使用UIStackView
呢?我支持使用UIStackView,不管它值多少钱这让我更快乐。