Ios 如何获取Massiness为UIView声明的高度约束?
例如,我通过Ios 如何获取Massiness为UIView声明的高度约束?,ios,objective-c,uiview,autolayout,masonry,Ios,Objective C,Uiview,Autolayout,Masonry,例如,我通过砌体为UIView声明了一些约束: [replyTextView mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(44); make.left.right.bottom.equalTo(self.contentView); }]; 如何获取replyTextView的高度约束 我知道我可以使用replyTextView.constraints获取所有约束,但我不知道如何告诉它
砌体
为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
另请参见github Massey页面上的相关讨论:您是否厌倦了访问它?我尝试过,但失败了
MASConstraint
只是一个包装器抽象类,它可以设置偏移量,但不能读取常量。它可以工作,谢谢!还有一个问题,如果我使用此私钥,我的应用程序是否会在AppStore中被拒绝?“layoutConstraint”是MASViewConstraint类的自定义属性(即非私有iOS API),您的应用程序不会被拒绝只是意识到这可能更容易:CGFloat height=[[heightConstraint valueForKey:@“layoutConstant”]floatValue];[高度约束设置偏移:(高度+100)]代码>谢谢。但是我认为(NSLayoutConstraint*)constraint
不会响应floatValue
?在第二种情况下,它使用layoutConstant
而不是layoutConstraint
,请再次查看