【问题标题】:iOS Autolayout: Is it okay to set constraint priority to 999 to silence a warning?iOS Autolayout:可以将约束优先级设置为 999 以使警告静音吗?
【发布时间】:2018-08-01 01:20:40
【问题描述】:

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

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 来消除警告。这似乎消除了警告,并且布局没有任何变化。这样做可以吗?或者这会导致任何问题吗?

【问题讨论】:

  • 要正确解决这个问题,你需要弄清楚这个约束来自哪里:&lt;NSLayoutConstraint:0x60400028a1e0 'UIView-Encapsulated-Layout-Width' UIView:0x7fc908d52020.width == 0 (active)&gt;

标签: ios objective-c autolayout constraints


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-15
    • 1970-01-01
    • 2015-12-22
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多