Swift Xcode会试图通过打破约束来恢复吗?

时间:2017-08-21 06:32:22

标签: ios xcode

我在xCode Log上收到消息当我在我的应用程序由Swift 4开发的午餐时,我有tableview有多个不同的单元格关于12个不同的单元格,我得到的警告信息是:

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-08-21 09:27:57.404497+0300 muzeit[6449:2211903] [LayoutConstraints] 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:0x174481770 V:|-(0)-[UIImageView:0x107a09eb0]   (active, names: '|':UIView:0x107a09d10 )>",
    "<NSLayoutConstraint:0x174481860 V:[UIImageView:0x107a09eb0]-(-60)-|   (active, names: '|':UIView:0x107a09d10 )>",
    "<NSLayoutConstraint:0x1744818b0 UIImageView:0x107a09eb0.centerY == UIView:0x107a09d10.centerY   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x1744818b0 UIImageView:0x107a09eb0.centerY == UIView:0x107a09d10.centerY   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-08-21 09:27:57.492890+0300 muzeit[6449:2211903] [LayoutConstraints] 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:0x17048b770 V:|-(0)-[UIImageView:0x107a30c30]   (active, names: '|':UIView:0x107a30a90 )>",
    "<NSLayoutConstraint:0x17048b860 V:[UIImageView:0x107a30c30]-(-60)-|   (active, names: '|':UIView:0x107a30a90 )>",
    "<NSLayoutConstraint:0x17048b8b0 UIImageView:0x107a30c30.centerY == UIView:0x107a30a90.centerY   (active)>"
)

我试图谷歌找到一些解决方法如何解决它,我找不到明确的答案,断点也没有表明约束有问题!

任何想法?

2 个答案:

答案 0 :(得分:1)

如果您想更好地了解日志试图告诉您的内容,可以检查Visual Format Language。您可以按以下方式“翻译”您的日志:

V:|-(0)-[UIImageView:0x107a09eb0] =设置超级视图顶部(|)和ImageView之间的垂直(V :)点为0点

V:[UIImageView:0x107a09eb0]-(-60)-| =设置UIImageView底部和超级视图(|)之间的垂直(V :)空间为-60点

UIImageView:0x107a09eb0.centerY == UIView:0x107a09d10.centerY (active) =将UIImageView垂直居中放置在超级视图中

通过翻译,现在更容易理解UIImageView固定在顶部和底部,并且这与第三个约束(即试图将UIImageView垂直居中)相冲突。

如@ReinerMeilan在评论中所建议,您可以删除centerY约束以解决此自动布局问题。

答案 1 :(得分:-1)

您选择在功能中检查您的UI和tableView的大小,或者检查项目中的修复约束中心Y. 你应该删除一些约束,或者你可以从代码控制器中修改大小