简体   繁体   English

调试时“无法同时满足约束条件”

[英]“Unable to simultaneously satisfy constraints” when debugging

Below is the error message I receive in the debug area. 以下是我在调试区域中收到的错误消息。 It runs fine and nothing is wrong except that I receive this error. 它运行正常,除了我收到此错误外,没有什么错。 Would this prevent apple accepting the app? 这会阻止苹果接受该应用程序吗? How do I fix it? 我如何解决它?

( "<NSLayoutConstraint:0x7f9bdaf58890 UIView:0x7f9bdaf484e0.leading == UIView:0x7f9bdaf56e30.leadingMargin + 34>", "<NSLayoutConstraint:0x7f9bdaf58930 UIView:0x7f9bdaf56e30.trailingMargin == UIView:0x7f9bdaf484e0.trailing + 34>", "<NSLayoutConstraint:0x7f9bdaf58980 H:[UIView:0x7f9bdaf484e0(300)]>", "<NSLayoutConstraint:0x7f9bdaf5bfc0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7f9bdaf56e30(375)]>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x7f9bdaf58980 H:[UIView:0x7f9bdaf484e0(300)]>

I guess this happens in a UITableView on an iPhone 6. 我猜这发生在iPhone 6的UITableView

Since cells reach from the left edge of the tableView to the right edge the cells need to be 375 points wide. 由于单元格从tableView的左边缘到达右边缘,因此单元格需要为375点宽。 The UITableView adds the UIView-Encapsulated-Layout-Width constraint to achieve this. UITableView添加了UIView-Encapsulated-Layout-Width约束来实现此目的。

The constraints you added yourself |-34-[centerView(=300)]-34-| 您添加的约束条件|-34-[centerView(=300)]-34-| will create a cell width of 368 points. 将创建一个368点的单元格宽度。

Since 368 != 375 this won't work. 由于368!= 375,因此无法使用。

You have a couple of options. 您有两种选择。

  1. Turn your constraints into in-equal constraints, ie make the width of the centered view "greater than or equal". 将您的约束变成不相等的约束,即使居中视图的宽度“大于或等于”。 In code that would look like this: |-34-[centerView(>=300)]-34-| 在看起来像这样的代码中: |-34-[centerView(>=300)]-34-|
  2. Constrain your centerView with a "horizontal center in container" constraint, keep the width constraint and get rid of the edge-distance constraints. 使用“容器中的水平中心”约束来约束centerView,保留宽度约束并摆脱边距约束。
  3. Get rid of the width constraint completely. 完全摆脱宽度约束。 The width will change depending on the cell width. 宽度将根据像元宽度而变化。 eg |-34-[centerView]-34-| 例如|-34-[centerView]-34-| , this will lead to a 307 pt wide view on iPhone 6, on iPhone 6s it will be 346 points wide and on iPhone 5 it'll be 252 points wide. ,这将导致在iPhone 6上获得307 pt的宽视角,在iPhone 6s上,它将宽346点,在iPhone 5上,它将宽252点。

As you said the app works if the systems breaks the width=300 constraint, so you can just delete that constraint yourself. 如您所说,如果系统打破width = 300约束,则该应用程序将运行,因此您可以自己删除该约束。 If it works without that constraint there is no point in having it. 如果没有限制,它就没有意义。

Having two edge-distance constraints AND a width constraints at the same time doesn't make sense and defeats the purpose of auto layout. 同时具有两个边缘距离约束和一个宽度约束没有意义,并且违反了自动布局的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM