OGeek|极客世界-中国程序员成长平台

标题: ios - Swift Xcode 会尝试通过打破约束来恢复吗? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:31
标题: ios - Swift Xcode 会尝试通过打破约束来恢复吗?

当我用 Swift 4 开发我的应用程序午餐时,我在 xCode 日志上收到消息,我的 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)>"
)

我试图用谷歌搜索它以找到一些解决方法,我找不到明确的答案,而且断点也没有显示约束有问题!

有什么想法吗?



Best Answer-推荐答案


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

V:|-(0)-[UIImageView:0x107a09eb0] = 在父 View 的顶部 (|) 和 ImageView 之间设置一个 0 点的垂直 (V 空间

V:[UIImageView:0x107a09eb0]-(-60)-| = 在 UIImageView 底部和父 View (|) 之间设置 -60 点的垂直 (V 空间

UIImageView:0x107a09eb0.centerY == UIView:0x107a09d10.centerY (active) = 垂直居中 UIImageView 到 superview

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

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

关于ios - Swift Xcode 会尝试通过打破约束来恢复吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45790601/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4