无法同时满足约束

其实集成摄像头应用程序使用XIB,在我把视图放在一个视图,之后,我把imageview,再次在imageview上查看裁剪。 然后运行项目我得到这个错误。

2013-07-23 12:45:49.936 Camera_App1 [30668:907]无法同时满足约束。 下面列表中的至less一个约束可能是你不想要的。 试试这个:(1)看看每一个约束,并试图找出你不期望的; (2)find添加不需要的约束或约束的代码并修复它。 (注意:如果您看到您不明白的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. 

这个错误就是它所说的,给出了相当明确的指示,让你开始debugging。 有两个约束冲突。 每个指示自动布局运行时做一些矛盾的事情。

如果以编程方式创build和添加视图,那么自动resize的属性已被自动转换为自动布局约束。

因此,首先要尝试的是,通过编程创build的视图,通过设置来禁用它:

 myProgrammaticView.translatesAutoresizingMaskIntoConstraints = NO; 

我遇到了同样的问题,经过几个小时的search,结果发现问题是因为通话或热点状态栏已被切换(热点在打电话),为了解决这个问题,我在appdelegate中补充道:

  func application(application: UIApplication, willChangeStatusBarFrame newStatusBarFrame: CGRect) { let windows = UIApplication.sharedApplication().windows for window in windows { window.removeConstraints(window.constraints) } } 

我知道这个线程很老,但这是我的经验和解决scheme。

select视图(UILabel,UIImage等)编辑器> Pin>(select…)到超级视图编辑器>解决自动布局问题>添加缺less约束

这个错误是在您添加的约束之间冲突。 删除不需要的约束。 不要在相同的方向和types上使用多个约束。

在这里输入图像说明

我会build议你使用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希望这是有帮助&#x7684;:)