iOS入门mesonry 更新约束注意点

Posted wp7ers

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS入门mesonry 更新约束注意点相关的知识,希望对你有一定的参考价值。

练习UI布局

 

 masonry 把下划线View移动左边。

开始时对齐中间的 lable ,点击时移动到对应lable下面。

使用方法:

    [indicator mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(curCurTab);
    }];
    

直接报错:

[LayoutConstraints] 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. 
(
    "<MASLayoutConstraint:0x600002860660 UILabel:0x7feeda8202e0.width == 60>",
    "<MASLayoutConstraint:0x600002860060 UILabel:0x7feeda820070.width == 60>",
    "<MASLayoutConstraint:0x600002860840 UILabel:0x7feeda820070.right == UILabel:0x7feeda8202e0.left>",
    "<MASLayoutConstraint:0x600002860cc0 UIView:0x7feeda820f10.centerX == UILabel:0x7feeda8202e0.centerX>",
    "<MASLayoutConstraint:0x600002845560 UIView:0x7feeda820f10.centerX == UILabel:0x7feeda820070.centerX>"
)

Will attempt to recover by breaking constraint 
<MASLayoutConstraint:0x600002860660 UILabel:0x7feeda8202e0.width == 60>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2020-01-13 17:08:47.697034+0800 UITabBarControllerTest[62772:3586985] [LayoutConstraints] 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. 
(
    "<MASLayoutConstraint:0x600002860060 UILabel:0x7feeda820070.width == 60>",
    "<MASLayoutConstraint:0x600002860840 UILabel:0x7feeda820070.right == UILabel:0x7feeda8202e0.left>",
    "<MASLayoutConstraint:0x600002860cc0 UIView:0x7feeda820f10.centerX == UILabel:0x7feeda8202e0.centerX>",
    "<MASLayoutConstraint:0x600002845560 UIView:0x7feeda820f10.centerX == UILabel:0x7feeda820070.centerX>"
)

 

原因:

参考这个https://blog.csdn.net/captainjackNO1/article/details/51275161

mas_updateConstraints方法里对同一个布局的理解就是相对的元素也是一致才行,即这里这样做才算一次update

A->B A->B的变化
A->C 是一个新的约束

 

或者 

使用:

mas_remakeConstraints 重做约束。
    [indicator mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(curCurTab);
        make.bottom.equalTo(tabLayout.mas_bottom).offset(-2);
        make.height.equalTo(@3);
        make.width.equalTo(@15);
    }];

以上是关于iOS入门mesonry 更新约束注意点的主要内容,如果未能解决你的问题,请参考以下文章

iOS代码添加视图约束

iOS 更新 TableViewCell 约束

Cg入门19:Fragment shader - 片段级模型动态变色

关于 iOS 约束更新动画 - 动画块 + layoutIfNeeded

SnapKit 更新约束导致冲突

小程序各种功能代码片段整理---持续更新