繁体   English   中英

无法同时满足约束

[英]Unable to simultaneously satisfy constraints

实际上使用xib集成了相机应用程序,我将uiview放在视图上,之后我将imageview,再次在imageview上查看以进行裁剪。 然后运行项目我收到此错误。

2013-07-23 12:45:49.936 Camera_App1 [30668:907]无法同时满足约束条件。 可能至少下列列表中的一个约束是您不想要的约束。 试试这个:(1)看看每个约束并试着找出你不期望的东西; (2)找到添加了不需要的约束或约束的代码并修复它。 (注意:如果您看到您不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性的文档translatesAutoresizingMaskIntoConstraints)

(
    "<NSAutoresizingMaskLayoutConstraint:0x1f5b3d10 h=--& v=--& V:[UIView:0x1f5a2f70(460)]>",
    "<NSLayoutConstraint:0x1f5a3c80 V:[UIView:0x1f5a31b0]-(385)-|   (Names: '|':UIView:0x1f5a3120 )>",
    "<NSLayoutConstraint:0x1f5a3f80 V:|-(0)-[UIView:0x1f5a3120]   (Names: '|':UIView:0x1f5a2f70 )>",
    "<NSLayoutConstraint:0x1f5a3f40 V:[UIView:0x1f5a3120]-(63)-|   (Names: '|':UIView:0x1f5a2f70 )>",
    "<NSLayoutConstraint:0x1f5a3bc0 V:|-(61)-[UIView:0x1f5a31b0]   (Names: '|':UIView:0x1f5a3120 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x1f5a3c80 V:[UIView:0x1f5a31b0]-(385)-|   (Names: '|':UIView:0x1f5a3120 )>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2013-07-23 12:45:58.697 Camera_App1[30668:907] media type=public.image
2013-07-23 12:45:58.701 Camera_App1[30668:907] global=public.image
2013-07-23 12:45:58.858 Camera_App1[30668:907] 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:0x1f5a3c80 V:[UIView:0x1f5a31b0]-(385)-|   (Names: '|':UIView:0x1f5a3120 )>",
    "<NSLayoutConstraint:0x1f5a3f80 V:|-(0)-[UIView:0x1f5a3120]   (Names: '|':UIView:0x1f5a2f70 )>",
    "<NSLayoutConstraint:0x1f5a3f40 V:[UIView:0x1f5a3120]-(63)-|   (Names: '|':UIView:0x1f5a2f70 )>",
    "<NSLayoutConstraint:0x1f5a3bc0 V:|-(61)-[UIView:0x1f5a31b0]   (Names: '|':UIView:0x1f5a3120 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x1f53a430 h=--& v=--& V:[UIView:0x1f5a2f70(460)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x1f5a3c80 V:[UIView:0x1f5a31b0]-(385)-|   (Names: '|':UIView:0x1f5a3120 )>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

错误就是它所说的,并为您提供了非常明确的指令供您开始调试。 有两个冲突的约束。 每个都指示自动布局运行时执行与另一个相矛盾的操作。

如果以编程方式创建和添加视图,则自动调整大小属性可能会自动转换为自动布局约束。

因此,首先要尝试的是,使用以编程方式创建的视图,通过设置禁用此功能:

myProgrammaticView.translatesAutoresizingMaskIntoConstraints = NO;

我遇到了同样的问题,经过几个小时的搜索,结果发现问题是因为拨打电话或热点状态栏,(热点已开启,在电话中),以解决问题,在appdelegate中我添加了:

    func application(application: UIApplication, willChangeStatusBarFrame newStatusBarFrame: CGRect) {
    let windows = UIApplication.sharedApplication().windows

    for window in windows {
        window.removeConstraints(window.constraints)
    }
}

我知道这个帖子很老,但这是我的经验和解决方案。

选择视图(UILabel,UIImage等)编辑器> Pin>(选择...)到Superview编辑器>解决自动布局问题>添加缺失约束

此错误是您添加的约束之间的冲突。 删除不需要的约束。 不要在同一方向和类型中使用多个约束。

在此输入图像描述

我建议你使用SnapKit。 它是一个Autolayout框架,使用起来非常方便

 import SnapKit

 var label = UILabel()

 label.snp_makeConstraints { (make) -> Void in
    make.centerX.equalTo(0)
    make.centerY.equalTo(0)
    make.width.equalTo(30)
    make.height.equalTo(30)
 }

https://github.com/SnapKit/SnapKit希望这有帮助:)

试试这个步骤,它对我有帮助。

选择对象>编辑器>解决自动布局问题>重置为建议约束

在此输入图像描述

在我的情况下,由于导航栏我得到了这个错误。 添加新的UIViewController导致此错误。

我删除了旧的导航栏,然后转到编辑器嵌入导航控制器重新添加它。

我重置为建议的约束,它解决了这个问题, 请看这里。

选择对象>编辑器>解决自动布局问题>重置为建议约束

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM