ios 无法同时满足约束

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17803801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 00:28:24  来源:igfitidea点击:

Unable to simultaneously satisfy constraints

iphoneiosobjective-c

提问by Thanush Shre

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. then run the project I got this error.

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

2013-07-23 12:45:49.936 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)

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.

回答by Max MacLeod

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.

如果您以编程方式创建和添加视图,那么 Auto Resizing 属性可能已自动转换为 Auto Layout 约束。

So, the first thing to try is, with your programmatically created views, disable this by setting:

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

myProgrammaticView.translatesAutoresizingMaskIntoConstraints = NO;

回答by Omar Albeik

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)
    }
}

回答by cyber8200

Try this steps, it helps me.

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

Select your object > Editor > Resolve Auto Layout Issues > Reset to Suggested Constraints

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

enter image description here

在此处输入图片说明

回答by Milap Jhumkhawala

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 等)编辑器 > 固定 >(选择...)到超级视图编辑器 > 解决自动布局问题 > 添加缺少的约束

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.

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

enter image description here

在此处输入图片说明

I would recommend that you use SnapKit. It is an Autolayout framework, very convenient to use

我建议您使用 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/SnapKitHope this is helpful:)

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

回答by Ankit Saxena

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 Editor? Embed In? Navigation Controller.

我删除了旧的导航栏,然后通过转到Editor重新添加它 ?嵌入导航控制器

回答by Nomad Qaderi

I reset to suggested Constraints and it resolved the issue, see here.

我重置为建议的约束并解决了问题,请参见此处。

Select your object > Editor > Resolve Auto Layout Issues > Reset to Suggested Constraints

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