Masonry父容器根据自容器宽度自适应报错

说明

在做一个UI界面中,开发了一个常见的布局,就是父容器根据自容器的宽度自适应,具体说明是:2的部分根据3的文字宽度来自适应,1根据2的宽度再自适应,如题如下:


Masonry父容器根据自容器宽度自适应报错_第1张图片
111.png

但是添加好约束后报约束错误:

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.
(
,
,
,
,
,
)

具体原因是:是最外层1的容器本身没有约束,导致的问题,
解放方案:将1的那个view设置个属性translatesAutoresizingMaskIntoConstraints

// 将1的那个view,在这个页面中是navigationItem.titleView,进行下面的设置
xxx.translatesAutoresizingMaskIntoConstraints = NO;

参考:translatesAutoresizingMaskIntoConstraints 详解

你可能感兴趣的:(Masonry父容器根据自容器宽度自适应报错)