首页 > 解决方案 > iOS Autolayout:可以将约束优先级设置为 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 来消除警告。这似乎消除了警告,并且布局没有任何变化。这样做可以吗?或者这会导致任何问题吗?

标签: iosobjective-cautolayoutconstraints

解决方案


这样做可以吗?或者这会导致任何问题吗?要看。可能会导致问题。

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

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

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


推荐阅读