NSLayoutConstraint - "将尝试通过违反约束来恢复#34;

时间:2015-06-30 22:35:49

标签: ios swift autolayout nslayoutconstraint

我正在开发自定义iOS键盘。我想将键盘视图分为顶部和底部的两个视图以及中间的滚动视图。我有topView和bottomView设置,但是当我尝试添加中间scrollView时,存在布局问题。这是我想要创建的布局图片。绿色是topView,蓝色是scrollView,红色是bottomView。

要设置中间scrollView,我将左右约束设置为包含视图的左右边缘。顶部和底部边缘分别设置在topView的底部和bottomView的顶部。这是我绘制中间滚轮的代码:

self.tileScrollView = UIScrollView()
self.tileScrollView.sizeToFit()
self.tileScrollView.setTranslatesAutoresizingMaskIntoConstraints(false)
self.tileScrollView.backgroundColor=UIColor.blueColor()

var leftSideConstraint = NSLayoutConstraint(item: self.tileScrollView, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1.0, constant: 0.0)
var rightSideConstraint = NSLayoutConstraint(item: self.tileScrollView, attribute: .Right, relatedBy: .Equal, toItem: self.view, attribute: .Right, multiplier: 1.0, constant: 0.0)
var topSideConstraint = NSLayoutConstraint(item: self.tileScrollView, attribute: .Top, relatedBy: .Equal, toItem: self.topView, attribute: .Bottom, multiplier: 1.0, constant: 0.0)
var bottomSideConstraint = NSLayoutConstraint(item: self.tileScrollView, attribute: .Bottom, relatedBy: .Equal, toItem: self.bottomView, attribute: .Top, multiplier: 1.0, constant: 0.0)

self.view.addSubview(self.tileScrollView)

self.view.addConstraints([leftSideConstraint, rightSideConstraint, topSideConstraint, bottomSideConstraint])

值得注意的是,当约束被破坏时,键盘会正确呈现。这是错误输出:

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:0x60800008f5f0 UIView:0x7f8c33f03740.bottom == UIInputView:0x7f8c33c09c20.top + 30>",
"<NSLayoutConstraint:0x60800008f7d0 V:[UIInputView:0x7f8c33c09c20]-(-30)-[UIView:0x7f8c33f03cb0]>",
"<NSLayoutConstraint:0x60800008fb40 V:[UIView:0x7f8c33f03740]-(0)-[UIScrollView:0x7f8c33f03dc0]>",
"<NSLayoutConstraint:0x60800008fb90 UIScrollView:0x7f8c33f03dc0.bottom == UIView:0x7f8c33f03cb0.top>",
"<NSLayoutConstraint:0x60000008e7e0 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x7f8c33c09c20(0)]>"
)
Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x60800008fb40 V:[UIView:0x7f8c33f03740]-(0)-[UIScrollView:0x7f8c33f03dc0]>

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.

有没有人对此错误有任何见解?

由于

0 个答案:

没有答案