Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 以编程方式设置约束会导致Swift中的冲突_Ios_Swift2_Constraints_Nslayoutconstraint_Programmatically Created - Fatal编程技术网

Ios 以编程方式设置约束会导致Swift中的冲突

Ios 以编程方式设置约束会导致Swift中的冲突,ios,swift2,constraints,nslayoutconstraint,programmatically-created,Ios,Swift2,Constraints,Nslayoutconstraint,Programmatically Created,正如我在中发布的,我遇到了一些隐藏约束的问题,每当我尝试添加自己的约束时,这些约束都会抛出错误 2016-04-18 19:22:04.270 Metric Time[1519:447809] 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) l

正如我在中发布的,我遇到了一些隐藏约束的问题,每当我尝试添加自己的约束时,这些约束都会抛出错误

2016-04-18 19:22:04.270 Metric Time[1519:447809] 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)
(
"<NSAutoresizingMaskLayoutConstraint:0x15e670e70 h=--& v=--& Metric_Time.View:0x15e692e70.midX == + 115>",
"<NSLayoutConstraint:0x15e5048c0 Metric_Time.View:0x15e692e70.centerX == UIView:0x15e6953e0.centerX>",
"<NSAutoresizingMaskLayoutConstraint:0x15e55fd30 h=-&- v=-&- 'UIView-Encapsulated-Layout-Left' H:|-(0)-[UIView:0x15e6953e0]   (Names: '|':UIWindow:0x15e688ed0 )>",
"<NSLayoutConstraint:0x15e54e750 'UIView-Encapsulated-Layout-Width' H:[UIView:0x15e6953e0(320)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x15e5048c0 Metric_Time.View:0x15e692e70.centerX == UIView:0x15e6953e0.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.`
2016-04-18 19:22:04.270公制时间[1519:447809]无法同时满足约束条件。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助`
我试图寻找这些约束可能已创建的位置,但在我的
ViewController.swift
文件中搜索约束、布局等关键字时,只找到了我编写的代码


如果有人想搞乱我的代码,我的代码都是打开的。

如果要以编程方式添加约束,则需要关闭TranslateAutoResizengMaskinToConstraints。您也没有足够的约束来满足布局引擎。请记住,UIView没有固有的大小,如果对视图使用自动布局,则需要使用约束设置所有内容,而不是依赖约束和框架的混合。一种可能的解决方案是添加一些代码,如:

        self.view.addSubview(clockView)
        clockView.translatesAutoresizingMaskIntoConstraints = false
        clockView.centerYAnchor.constraintEqualToAnchor(self.view.centerYAnchor, constant: 0.0).active = true
        clockView.centerXAnchor.constraintEqualToAnchor(self.view.centerXAnchor, constant: 0.0).active = true
        clockView.widthAnchor.constraintEqualToConstant(230.0).active = true
        clockView.heightAnchor.constraintEqualToConstant(230.0).active = true

然而,这并不完全是你想要的,因为当它是在横向时,你的时钟覆盖着你的标签。但是你可以通过玩
clockView.centerYAnchor.constrainteQualtoancher(self.view.centerYAnchor,常量:0.0).active=true来解决这个问题

如果我在
UIDatePicker()
上使用这个怎么办?你也可以做同样的事情,但是用datePicker替换clockView。您也不需要添加宽度和高度约束,因为UIDatePicker有一个固有的大小。好的,还有@beyowulf,当我检查视图层次结构时,我的UIDatePicker看起来有点奇怪。。。我做错了什么?@ACE这就是UIPickerViews的实现方式。你不必担心,一般来说,苹果的框架是高度优化和健壮的。我打开了一个拉请求你的回购,你应该考虑这些变化。是否有一个iOS 8兼容的方式来做到这一点?