十分感谢一下博客让我解决了问题:
ios 约束冲突NSAutoresizingMaskLayoutConstraint
最近手写约束布局代码,适配不同屏幕的时候,出现了一个很奇怪的问题,不报错也不崩溃,最终的效果也是理想的,但就是出警告。原因是约束的大小不固定,需要根据屏幕的比例大小进行相应的变值。
程序是在iPhone5s上进行的开发,在那个时候是没有问题的,但运行在iPhone6s的时候,就会出现下面的警告,但运行的结果是理想中的效果:
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2016-05-05 14:10:20.354 IGO[5581:2754283] 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.
(
"<NSLayoutConstraint:0x13a093200 V:|-(10)-[UIImageView:0x13a0922d0] (Names: '|':YBChildCell:0x13a08a8b0'YBChildObject' )>",
"<NSLayoutConstraint:0x13a093280 V:[UIImageView:0x13a0922d0(82.0312)]>",
"<NSLayoutConstraint:0x13a0932d0 V:[UIImageView:0x13a0922d0]-(10)-| (Names: '|':YBChildCell:0x13a08a8b0'YBChildObject' )>",
"<NSLayoutConstraint:0x13a09a2f0 'UIView-Encapsulated-Layout-Height' V:[YBChildCell:0x13a08a8b0'YBChildObject'(102)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x13a0932d0 V:[UIImageView:0x13a0922d0]-(10)-| (Names: '|':YBChildCell:0x13a08a8b0'YBChildObject' )>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
大体的意思就是约束出现冲突,看到这个警告的第一个反应就是组件的translatesAutoresizingMaskIntoConstraints
属性没有设置为false
,但是检查过后,没有出现这个错误。
虽然不影响最终的布局,但每次一运行就爆出那么多的警告,着实觉得非常的不好,于是百度了一下,从而解决方法如下:
找到提示冲突的语句
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x13a0932d0 V:
[UIImageView:0x13a0922d0]-(10)-| (Names:
'|':YBChildCell:0x13a08a8b0'YBChildObject' )>
调整此约束的优先级,如下:
NSArray * ver1 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[_headImageView(imageHeight)]-10-|"
options:0 metrics:metriceDictionary views:NSDictionaryOfVariableBindings(_headImageView)];
[ver1.firstObject setPriority:UILayoutPriorityDefaultHigh];//修改优先级
这样就不会出现那个警告了,具体原因,楼主表示真的不清楚,因为布局来看,是没有任何冲突的,如果有知道的人,也请告知一下…Thanks()