iOS自动布局:可以将约束优先级设置为999以静音警告吗



我收到以下关于自动布局的警告。

Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. 
Try this: 
(1) look at each constraint and try to figure out which you don't expect; 
(2) find the code that added the unwanted constraint or constraints and fix it. 
(
"<NSLayoutConstraint:0x604000285230 H:|-(64)-[UILabel:0x7fc908d51ba0]   (active, names: '|':UIView:0x7fc908d52020 )>",
"<NSLayoutConstraint:0x6040002854b0 H:[UIView:0x7fc908c59f60]-(0)-|   (active, names: '|':UIView:0x7fc908d52020 )>",
"<NSLayoutConstraint:0x604000285000 H:[UILabel:0x7fc908d51ba0]-(9)-[UIView:0x7fc908c59f60]   (active)>",
"<NSLayoutConstraint:0x6040002855f0 UIView:0x7fc908c59f60.width == 160   (active)>",
"<NSLayoutConstraint:0x60400028a1e0 'UIView-Encapsulated-Layout-Width' UIView:0x7fc908d52020.width == 0   (active)>"
)

但是,我可以通过将尾随约束优先级设置为999来静音警告。这似乎删除了警告,并且没有更改任何有关布局的内容。这样做可以吗?还是会引起任何问题?

这样做可以吗?还是会导致任何问题?取决于。可能会引发问题。

理想的方法是不破坏您修复警告的约束。问题似乎与约束有关。

"<NSLayoutConstraint:0x60400028a1e0 'UIView-Encapsulated-Layout-Width' UIView:0x7fc908d52020.width == 0   (active)>"

您的超级视图(0x7fc908d52020(正在强制宽度为0。可能是你不想要的东西。

最新更新