2013-07-23 178 views
9

实际上集成摄像头应用程序使用xib,因为我在视图上放置uview,之后我把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. 
+3

我想downvote意见。真的。 –

+1

@MatthiasBauch将它标记为非建设性的。 – JustSid

+1

可能的重复[在Xcode中获取有关约束的怪异错误](http://stackoverflow.com/questions/11664115/getting-weird-error-talking-about-constraints-in-xcode) –

回答

20

的错误是它说什么,并给出了非常明确的指示,为您开始调试。有两个约束冲突。每个指示自动布局运行时执行与另一个相矛盾的事情。

如果您正在以编程方式创建和添加视图,那么很可能自动调整大小属性已自动转换为自动布局约束。

因此,尝试的第一件事是,你的程序创建的视图,通过设置禁用此:

myProgrammaticView.translatesAutoresizingMaskIntoConstraints = NO; 
+0

如果我想使用一个没有任何约束的特定视图,我该如何避免警告... – Leena

+0

如果视图没有约束,那么将不会有任何警告 –

+0

我想要一起约束我想使用自动调整面具没有警告。 – Leena

4

我有同样的问题,搜索了几个小时之后,原来的问题是因为在-call或热点状态栏被触发,(热点上,在电话),来解决这个问题,在我的appdelegate说:

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

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

谢谢!这也解决了我的问题。但是,当我尝试另一种情况时,请打开通话状态栏(更宽的绿色栏),然后启动应用程序,尝试切换它,再次看到错误。你看到一样吗? –

0

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

选择视图(的UILabel,UIImage的等)编辑器>针>(选择...),以上海华编辑>解决自动布局问题>添加缺少的约束

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

enter image description here

我会建议你使用SnapKit。这是一个自动布局框架,使用起来非常方便

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希望这是有益:)

相关问题