ios - 如何使用 Masonry mas_makeConstraints 避免冲突?

标签 ios autolayout constraints masonry

[self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_line.superview).multipliedBy(0.5);
    }];

[self.line mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_line.superview).multipliedBy(1.66666);
    }];

    "<MASLayoutConstraint:0x14efa7170 UIView:0x14ef3f5a0.centerY == UIView:0x14ef3ec00.centerY * 0.5>",
    "<MASLayoutConstraint:0x15026dcb0 UIView:0x14ef3f5a0.centerY == UIView:0x14ef3ec00.centerY * 1.66666>"

当我尝试更新约束时,会发生冲突,如何正确使用?

看起来更新操作创建了一个新的约束而不是改变它的值。

不能应用在mas_updateConstraints中吗?

我必须使用 mas_remakeConstraints 吗?

最佳答案

苹果文档说:

Unlike the other properties, the constant may be modified after constraint creation. Setting the constant on an existing constraint performs much better than removing the constraint and adding a new one that's just like the old but for having a new constant.

让我们在下面粘贴一些原始约束:

[NSLayoutConstraint constraintWithItem:view1
                                 attribute:NSLayoutAttributeTop
                                 relatedBy:NSLayoutRelationEqual
                                    toItem:superview
                                 attribute:NSLayoutAttributeTop
                                multiplier:1.0
                                  constant:padding.top]

根据docmas_updateConstraints 应该更改现有约束的常数 值,但是,乘数不是常数部分。

根据 doc 改为使用 mas_remakeConstraints , 在安装新的之前删除所有现有的。

关于ios - 如何使用 Masonry mas_makeConstraints 避免冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38179894/

相关文章:

ios - 快速导航 View Controller 时倒计时计时器不起作用?

objective-c - iOS - 自动布局的比例间距

unit-testing - 有没有一种不太臃肿的方法来测试 grails 中的约束?

ios - 如何知道您的 .ipa 是否为 64 位

ios - UIView嵌入UIScrollView教程

ios - 如何在 iOS 10 Swift 3 中创建水平轮播

ios - 如何将 AutoLayout 与 transform 一起使用

ios - UIStackView 可以被约束吗?

ios - 即时更改 UI - iOS

database - Postgresql 中的约束