美文网首页iOS开发资料收集区iOS开发技术
ios 约束冲突NSAutoresizingMaskLayout

ios 约束冲突NSAutoresizingMaskLayout

作者: 三十一_iOS | 来源:发表于2015-11-30 11:26 被阅读5945次
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) 
(
    "<MASLayoutConstraint:0x7fafcb1c8e10 UIButton:0x7fafcb18e160.width == UIView:0x7fafcb0bd380.width - 60>",
    "<NSAutoresizingMaskLayoutConstraint:0x7fafcb0a2570 UIView:0x7fafcb0bd380.width == 0>"
)

Will attempt to recover by breaking constraint 
<MASLayoutConstraint:0x7fafcb1c8e10 UIButton:0x7fafcb18e160.width == UIView:0x7fafcb0bd380.width - 60>

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.

在手撸约束的时间,经常会碰到类似的约束警告,其实对布局显示是没有影响的,但是看到这个警告真是蛋疼的要死啊,整个人的心情都不好了,怎么办?谷歌百度啊。

结果如下:

当你决定在你的项目中大规模使用AutoLayout时,那么NSAutoresizingMaskLayoutConstraint大部分情况下是非常不和谐的东西,它通常会把你的程序搞崩溃,幸好IB中的View不会出现这个问题,如果你使用代码添加了view并且出现了NSAutoresizingMaskLayoutConstraint相关的问题,你应该将该View的translatesAutoresizingMaskIntoConstraints设置为NO。

再次编辑,又遇到了这个扯淡的问题,按照上面的方法,可以消除警告,但是现实的宽度不对了。

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}span.s1 {font-variant-ligatures: no-common-ligatures}span.Apple-tab-span {white-space:pre}

**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:0x7fdfc403ec90 MeHeadView:0x7fdfc4069730.trailing == UILabel:0x7fdfc40900d0.trailing + 20>",**
**    "<NSLayoutConstraint:0x7fdfc40a8210 UILabel:0x7fdfc40900d0.leading == MeHeadView:0x7fdfc4069730.leading + 20>",**
**    "<NSLayoutConstraint:0x7fdfc1d6c250 MeHeadView:0x7fdfc4069730.width == 0>"**
**)**
****
**Will attempt to recover by breaking constraint **
**<NSLayoutConstraint:0x7fdfc403ec90 MeHeadView:0x7fdfc4069730.trailing == UILabel:0x7fdfc40900d0.trailing + 20>**
****
**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.**

先修改如下

Paste_Image.png

把其中一个关于superview的约束从Required修改为High,就可以了;既消除了警告,也不影响视图的现实,但是我不知道是为什么!!!!!


2018/03/20
断断续续的还有人看到这个文章,后续在写一点吧。

出现这样的警告一般是因为视图的约束条件之间有冲突,譬如:视图有两个约束条件,一个是条件A要求视图的宽度大于 200,另一个条件B要求视图的宽度小于等于他的父视图,如果不设置优先级,当父视图的宽度小于 200 时,A 条件和B条件之间就发生了冲突,系统不知道采用那个约束条件的情况下就会产生警告。而修改了优先级以后,会告诉系统,如果条件之间有冲突,优先满足优先级高的那个条件。

相关文章

  • ios 约束冲突NSAutoresizingMaskLayout

    在手撸约束的时间,经常会碰到类似的约束警告,其实对布局显示是没有影响的,但是看到这个警告真是蛋疼的要死啊,整个人的...

  • iOS定位处理约束冲突

    iOS定位处理约束冲突[https://juejin.im/post/6844903618722660365]

  • iOS约束冲突问题

    在TableViewCell自适应高度的时候,报一大堆约束冲突错误,可尝试调整最后一个试图对cell的约束级别

  • iOS 约束冲突解决

    AutoLayout使用起来方便快捷,但是当我们的约束设置出现冲突的时候就是非常蛋疼的时候了,下面说说我解决约束冲...

  • iOS UITableViewCell自身约束冲突

    遇到的问题:1.translatesAutoresizingMaskIntoConstraints问题 这个问题是...

  • iOS 快速定位约束冲突

    快速定位约束冲突一般简单界面冲突,我们很容易根据提示找到对应的 View, 但是当你视图层次很深(比如使用 Col...

  • 快速定位Mas的约束冲突

    iOS定位处理约束冲突- 简书 安装并搭建: facebook/chisel 1. brew update(也可以...

  • iOS定位处理约束冲突

    前言 在做项目的时候,无意间看到自动布局约束警告,开始也也觉得没什么,虽然有警告,但并不影响UI展示效果。但是越来...

  • iOS Masonry使用总结

    Masonry布局定位约束冲突 视图布局添加约束的时候,有的时候会报一对约束冲突:Probably at leas...

  • OC - Masonry-Debugging Helpers/b

    在约束的后面加上key - 当此条约束与其它约束冲突时, 调试台会明确指出此key的约束出现冲突. firstBa...

网友评论

  • UnitedStates:楼主你拯救了我的一天啊!!!感谢你!!!
    虽然我还是不知道为什么要这样做,但是毫无疑问它拯救了我这样的强迫症患者.
    如果能知道这样改的原因是什么就好了,难道又是苹果扔出来的一枚bug?
    三十一_iOS:不是 bug ,这样写一般是因为 视图的约束之间有冲突,譬如:视图有两个约束条件,一个是条件A要求视图的宽度大于 200,另一个条件B要求视图的宽度小于等于他的父视图,如果不设置优先级,当父视图的宽度小于 200 时,A 条件和B条件之间就发生了冲突,x系统不知道采用那个约束条件的情况下就会产生警告。而修改了优先级以后,会告诉系统,如果条件之间有冲突,优先满足优先级高的那个条件。
  • 8c84350e5f8f:同问为什么
    三十一_iOS:约束冲突,不能确定视图的正确显示方式
  • SlimMan:我也遇到了,也是和你一样一改就好,不过解决了就行了
  • 龙伟17:反正一般遇到 类似问题 看不出来什么毛病 就改约束优先级别
    三十一_iOS:@龙红伟 :smiley:
  • Ths:我也遇到了- -为什么
    三十一_iOS:@Ths 我也是搞不清楚为什么。

本文标题:ios 约束冲突NSAutoresizingMaskLayout

本文链接:https://www.haomeiwen.com/subject/enljhttx.html