【发布时间】:2023-04-03 02:24:01
【问题描述】:
好的,我遇到了这个奇怪的问题(因为我以前从未见过这样的错误),我的视图中有一个 Textfield,我正在通过两侧的动画(尾随和前导)扩大它的宽度,但问题是这是它唯一从一侧扩展的吗(尾随或前导)
我的代码:
VIewController 类
@IBOutlet var constraint1: NSLayoutConstraint! // textfield's leading constraint
@IBOutlet var constraint2: NSLayoutConstraint! // textfield's trailing constraint
viewDidload(){........}
@IBAction func editingBegin(sender: AnyObject) {
fullnameTextField.layer.cornerRadius = 0
fullnameTextField.clipsToBounds = false
self.constraint2.constant = -16 // here i'm expanding the width by setting constant of my Textfield
self.constraint1.constant = -16
UIView.animateWithDuration(duration) {
self.fullnameTextField.layoutIfNeeded()
}
}
我的 NSlog 错误:
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:0x155e77fb0 UITextField:0x155d85e40.trailing == UIView:0x155e46800.trailingMargin>",
"<NSLayoutConstraint:0x1546b02b0 UITextField:0x155d85e40.leading == UIView:0x155e46800.leadingMargin - 16>",
"<NSLayoutConstraint:0x1546447e0 UITextField:0x155d85e40.centerX == UIView:0x155e46800.centerX>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1546447e0 UITextField:0x155d85e40.centerX == UIView:0x155e46800.centerX>
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.
这是我设置约束的情节提要
奇怪的是,我在另一个 View 控制器上做同样的事情,它在那里工作但不是在这里,我检查了每个约束它们是正确的,并且 NSLog 错误也出现在那个 ViewController 中(上面是工作正常)
有人知道这里有什么问题吗?请让我知道这太令人沮丧了
我的 ViewController 的代码http://pastebin.com/BvfEvzPE
【问题讨论】:
-
你的前导约束应该只有
16,而尾随是-16。 -
@DipenPanchasara 嘿伙计,你的回答成功了
-
谢谢。快乐编码:)
标签: ios swift2 constraints xcode-storyboard ios-autolayout