如何获取Masonry为UIView声明的高度约束?

How to get the height constraint declared by Masonry for UIView?

例如,我通过 Masonry 为 UIView 声明了一些约束:

[replyTextView mas_makeConstraints:^(MASConstraintMaker *make) {
  make.height.mas_equalTo(44);
  make.left.right.bottom.equalTo(self.contentView);
}];

如何获取 replyTextView 的高度限制?

我知道我可以使用 replyTextView.constraints 获取所有约束,但我不知道如何告诉它们。

如文档中所述:

   // in public/private interface
@property (nonatomic, strong) MASConstraint *heightConstraint;

...

// when making constraints
[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
    self.heightConstraint =  make.height.mas_equalTo(44);
}];

...
// then later you can call
[self.heightConstraint uninstall];

你可以这样做:

   // in public/private interface
@property (nonatomic, strong) MASConstraint *heightConstraint;

...

self.heightConstraint = [[replyTextView mas_makeConstraints:^(MASConstraintMaker *make) {
                            make.height.equalTo(@(44));
                            make.left.right.bottom.equalTo(self.contentView);
                        }] firstObject];//heightConstraint is first created MASConstraint
...

//heightConstraint is not composite MASConstraint, so we can access NSLayoutConstraint via KVC
NSLayoutConstraint *layoutConstraint = [heightConstraint valueForKey:@"layoutConstraint"];
CGFloat height = layoutConstraint.constant;//read
layoutConstraint.constant = height + 100;//modify

另见 Masonry github 页面上的相关讨论:https://github.com/SnapKit/Masonry/issues/206