ios - 激活 segue 时自动布局无法满足约束

标签 ios xcode swift

我有一个带有自动布局建议的约束的自定义表格 View 单元格。在 Storyboard中,所有约束都用蓝线标记,表示它们没有错误。 tableview 启动正常,布局正常,但只要我点击单元格激活 segue,我就会得到这个:

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.

我没有添加任何代码来为我的布局添加或删除约束。所有约束均由自动布局自动添加。

只有当我点击激活 segue 将用户带到下一个 View 的单元格时,才会出现错误。当我点击后退按钮时,tableview 返回但没有任何限制。

在 Attributes Inspector 中将 segue 设置为 Show(例如 Push)。

这是消息的其余部分:

    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7ff1c276fec0 UIImageView:0x7ff1c2496b40.top == UITableViewCellContentView:0x7ff1c2496630.topMargin + 15>",
    "<NSLayoutConstraint:0x7ff1c276ff10 UIImageView:0x7ff1c2496b40.centerY == UITableViewCellContentView:0x7ff1c2496630.centerY>",
    "<NSLayoutConstraint:0x7ff1c24c9a70 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7ff1c2496630(43.5)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7ff1c276ff10 UIImageView:0x7ff1c2496b40.centerY == UITableViewCellContentView:0x7ff1c2496630.centerY>

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.
2015-01-06 11:35:58.645 FitLift[4174:130902] 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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7ff1c2494c00 UIImageView:0x7ff1c277c070.top == UITableViewCellContentView:0x7ff1c277bfa0.topMargin + 15>",
    "<NSLayoutConstraint:0x7ff1c24a3360 UIImageView:0x7ff1c277c070.centerY == UITableViewCellContentView:0x7ff1c277bfa0.centerY>",
    "<NSLayoutConstraint:0x7ff1c24b7010 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7ff1c277bfa0(43.5)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7ff1c24a3360 UIImageView:0x7ff1c277c070.centerY == UITableViewCellContentView:0x7ff1c277bfa0.centerY>

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.
2015-01-06 11:35:58.646 FitLift[4174:130902] 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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7ff1c24c4390 UIImageView:0x7ff1c24bc880.top == UITableViewCellContentView:0x7ff1c24bc3d0.topMargin + 15>",
    "<NSLayoutConstraint:0x7ff1c24c43e0 UIImageView:0x7ff1c24bc880.centerY == UITableViewCellContentView:0x7ff1c24bc3d0.centerY>",
    "<NSLayoutConstraint:0x7ff1c24c7880 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7ff1c24bc3d0(43.5)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7ff1c24c43e0 UIImageView:0x7ff1c24bc880.centerY == UITableViewCellContentView:0x7ff1c24bc3d0.centerY>

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.

最佳答案

从错误日志来看,这两个相互冲突的约束似乎是 ImageView 的顶部约束和中心 Y 约束。只选择一个——iOS 混淆了分配给 ImageView 的 y 坐标的值。你想让 ImageView 离顶部一定距离,还是离父 View 的垂直中心一定距离?

作为一般规则,如果您希望您的 UI 看起来像您想要的那样,请不要让 Xcode 为您自动添加约束。自己定义。我们在这里无法真正帮助您,因为我们不知道 Xcode 添加但不冲突的其他约束。

关于ios - 激活 segue 时自动布局无法满足约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27790274/

相关文章:

ios - 通用 Storyboard上的字体大小

ios - ABMSoundCloudAPI : Convert Objective-C block to Swift closure

ios - 如何在Swift中从输入音频文件生成反相音频文件?

ios - 当用户滚动到不同页面时,如何在 `UICollectionView` 的不同背景颜色之间淡入淡出?

ios - 通过单击 TableView 中的单元格打开新的 View Controller - Swift iOS

ios - swift 4 : TimeInterval set to random number each time

ios - 如何比较两个数组以获得相似对象的数量?

ios - 使用 CocoaPod 依赖构建 Cocoa Touch Framework,不要嵌入

ios - 如何在 iOS 中为多个动态按钮和标签设置自动布局?

swift - MapView 优于 UITableViewCell