【发布时间】:2015-12-16 06:00:57
【问题描述】:
我创建了一个 uilable 和 uibutton
@IBOutlet weak var label_one: UILabel!
@IBOutlet weak var btn_one: UIButton!
并设置以下尾随和前导约束
self.btn_one.translatesAutoresizingMaskIntoConstraints=false
let contariants=NSLayoutConstraint(item:self.view,attribute:NSLayoutAttribute.LeadingMargin , relatedBy: NSLayoutRelation.Equal, toItem: btn_one, attribute: NSLayoutAttribute.LeadingMargin, multiplier: 1.0, constant: 20)
let trailingConstraints=NSLayoutConstraint(item: self.view, attribute:NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: btn_one, attribute:NSLayoutAttribute.Trailing , multiplier: 1.0, constant:20 )
self.view.addConstraint(contariants)
self.view.addConstraint(trailingConstraints)
// 但它根本不起作用并给出以下警告 以下列表中的至少一个约束可能是您不想要的。 试试这个: (1)查看每个约束并尝试找出您不期望的; (2) 找到添加了一个或多个不需要的约束的代码并修复它。 ( "", “UIButton:0x7ff8c84b0b60'Button'(名称:'|':UIView:0x7ff8c85226d0)>” )
将尝试通过打破约束来恢复
在 UIViewAlertForUnsatisfiableConstraints 创建一个符号断点,以便在调试器中捕获它。 中列出的 UIView 上的 UIConstraintBasedLayoutDebugging 类别中的方法也可能会有所帮助。 2015-12-16 10:39:01.918 ConstraintsExample [2635:38168] 无法同时满足约束条件。 以下列表中的至少一个约束可能是您不想要的。 试试这个: (1)查看每个约束并尝试找出您不期望的; (2) 找到添加了一个或多个不需要的约束的代码并修复它。 ( "", "UIButton:0x7ff8c84b0b60'Button' (名称: '|':UIView:0x7ff8c85226d0 )>", "", “” )
将尝试通过打破约束来恢复
在 UIViewAlertForUnsatisfiableConstraints 创建一个符号断点,以便在调试器中捕获它。 中列出的 UIView 上的 UIConstraintBasedLayoutDebugging 类别中的方法也可能会有所帮助。
【问题讨论】:
标签: ios swift nslayoutconstraint