简体   繁体   English

无法同时满足约束

[英]Unable to simultaneously satisfy constraints

Actually integrated camera application using xib, in that I placed uiview on a view, after that I put imageview, again view on imageview for cropping. 实际上使用xib集成了相机应用程序,我将uiview放在视图上,之后我将imageview,再次在imageview上查看以进行裁剪。 then run the project I got this error. 然后运行项目我收到此错误。

2013-07-23 12:45:49.936 Camera_App1[30668:907] Unable to simultaneously satisfy constraints. 2013-07-23 12:45:49.936 Camera_App1 [30668:907]无法同时满足约束条件。 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; 试试这个:(1)看看每个约束并试着找出你不期望的东西; (2) find the code that added the unwanted constraint or constraints and fix it. (2)找到添加了不需要的约束或约束的代码并修复它。 (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) (注意:如果您看到您不理解的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.

The error is what it says, and gives quite clear instructions for you to begin debugging. 错误就是它所说的,并为您提供了非常明确的指令供您开始调试。 There are two constraints that conflict. 有两个冲突的约束。 Each instructs the Auto Layout runtime to do something that contradicts the other. 每个都指示自动布局运行时执行与另一个相矛盾的操作。

If you are creating and adding views programmatically, then chances are Auto Resizing attributes have been automatically translated to Auto Layout constraints. 如果以编程方式创建和添加视图,则自动调整大小属性可能会自动转换为自动布局约束。

So, the first thing to try is, with your programmatically created views, disable this by setting: 因此,首先要尝试的是,使用以编程方式创建的视图,通过设置禁用此功能:

myProgrammaticView.translatesAutoresizingMaskIntoConstraints = NO;

I had the same problem, after hours of searching, it turned out the problem was because in-call or hotspot status bar was toggled, (hotspot is on, in a phone call), to fix the problem, in appdelegate I added: 我遇到了同样的问题,经过几个小时的搜索,结果发现问题是因为拨打电话或热点状态栏,(热点已开启,在电话中),以解决问题,在appdelegate中我添加了:

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

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

I know this thread is very old but this is my experience and Solution. 我知道这个帖子很老,但这是我的经验和解决方案。

Select view (UILabel, UIImage etc) Editor > Pin > (Select...) to Superview Editor > Resolve Auto Layout Issues > Add Missing Constraints 选择视图(UILabel,UIImage等)编辑器> Pin>(选择...)到Superview编辑器>解决自动布局问题>添加缺失约束

This error is to conflict between constraints that you have added. 此错误是您添加的约束之间的冲突。 Remove the constraints that are not required. 删除不需要的约束。 Not to use more than one constraint in the same direction and type. 不要在同一方向和类型中使用多个约束。

在此输入图像描述

I would recommend that you use SnapKit. 我建议你使用SnapKit。 It is an Autolayout framework, very convenient to use 它是一个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 Hope this is helpful:) https://github.com/SnapKit/SnapKit希望这有帮助:)

Try this steps, it helps me. 试试这个步骤,它对我有帮助。

Select your object > Editor > Resolve Auto Layout Issues > Reset to Suggested Constraints 选择对象>编辑器>解决自动布局问题>重置为建议约束

在此输入图像描述

In my case, I was getting this error due to a Navigation Bar. 在我的情况下,由于导航栏我得到了这个错误。 Adding New UIViewController was causing this error. 添加新的UIViewController导致此错误。

I removed the old navigation bar and then re-added it by going to EditorEmbed InNavigation Controller . 我删除了旧的导航栏,然后转到编辑器嵌入导航控制器重新添加它。

I reset to suggested Constraints and it resolved the issue, see here. 我重置为建议的约束,它解决了这个问题, 请看这里。

Select your object > Editor > Resolve Auto Layout Issues > Reset to Suggested Constraints 选择对象>编辑器>解决自动布局问题>重置为建议约束

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

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