iOS-为动态创建的视图设置适当的约束

iOS-为动态创建的视图设置适当的约束,ios,iphone,swift,constraints,Ios,Iphone,Swift,Constraints,我有这样的想法(很抱歉,这段代码很难看,只是为了测试): 当我运行应用程序时,我发现一个错误: 014-09-08 13:05:20.323 CutsomViewWithText[9123:3532873] 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)

我有这样的想法(很抱歉,这段代码很难看,只是为了测试):

当我运行应用程序时,我发现一个错误:

014-09-08 13:05:20.323 CutsomViewWithText[9123:3532873] 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:0x7ba39240 UIView:0x7a758e30.bottom == UIView:0x7a76d3e0.top + 10>",
"<NSAutoresizingMaskLayoutConstraint:0x7a74c470 h=--& v=--& UIView:0x7a758e30.midY == + 10>",
"<NSAutoresizingMaskLayoutConstraint:0x7a75c480 h=--& v=--& V:[UIView:0x7a758e30(0)]>",
"<NSAutoresizingMaskLayoutConstraint:0x7a76a990 h=--& v=--& UIView:0x7a76d3e0.midY == + 226.5>",
"<NSAutoresizingMaskLayoutConstraint:0x7a76a9c0 h=--& v=--& V:[UIView:0x7a76d3e0(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7ba39240 UIView:0x7a758e30.bottom == UIView:0x7a76d3e0.top + 10>

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.
2014-09-08 13:05:23.663 CutsomViewWithText[9123:3533398] Terminating since there is no system app.
014-09-08 13:05:20.323带有文本[9123:3532873]的视图无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。试着这样做:(1)看看每个约束,试着找出你不期望的约束;(2) 找到添加了不需要的约束的代码,然后修复它。(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2014-09-08 13:05:23.663由于没有系统应用程序,文本[9123:3533398]已终止的视图被剪切。

您能否帮助我,我应该如何在第一视图和第二视图之间设置适当的约束?

要为视图添加的约束类型

左侧、顶部、宽度和高度

左约束(示例):

myView1.SetTranslatesAutoResizengMaskintoConstraints(false) myView2.SetTranslatesAutoResizengMaskintoConstraints(false)

self.addConstraint(NSLayoutConstraint(


您需要添加以下代码行:

    emptyView.setTranslatesAutoresizingMaskIntoConstraints(false)
    emptyView2.setTranslatesAutoresizingMaskIntoConstraints(false)
以前

    var constraint = NSLayoutConstraint(item: emptyView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: emptyView2, attribute: NSLayoutAttribute.Top, multiplier: 1.0, constant: 10)
别忘了用合适的帧初始化emptyScrollView,否则会出现黑屏

    emptyView.setTranslatesAutoresizingMaskIntoConstraints(false)
    emptyView2.setTranslatesAutoresizingMaskIntoConstraints(false)
    var constraint = NSLayoutConstraint(item: emptyView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: emptyView2, attribute: NSLayoutAttribute.Top, multiplier: 1.0, constant: 10)