Masonry
Masonry copied to clipboard
困扰已久的问题,求指点
#import "Control.h" #import <Masonry.h>
@implementation Control{ UIView *topVIew; UILabel *label; UIView *bottomView; } [topVIew mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.right.mas_equalTo(0); make.height.mas_equalTo(100); }];
[bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.bottom.right.mas_equalTo(0);
make.height.mas_equalTo(100);
}];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(topVIew.mas_bottom);
make.bottom.mas_equalTo(bottomView.mas_top);
make.left.right.mas_equalTo(0);
}];
ViewController.m
-
(void)viewDidLoad { [super viewDidLoad];
_control = [[Control alloc]init]; _control.backgroundColor = [UIColor redColor]; [self.view addSubview:_control]; [_control mas_makeConstraints:^(MASConstraintMaker *make) { make.center.mas_equalTo(self.view); make.width.mas_equalTo(self.view).multipliedBy(0.8); make.height.mas_equalTo(300); }];
}
-
(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { _result = !_result; [self layoutControl]; }
-
(void)layoutControl { [_control mas_updateConstraints:^(MASConstraintMaker *make) { if (_result) { make.height.mas_equalTo(350); }else { make.height.mas_equalTo(300); } }]; [UIView animateWithDuration:0.25 animations:^{ [self.view layoutIfNeeded]; }];
}
这样修改的时候视图高度修改为什么会跳动?
在执行动画之前告诉系统你要更新约束,即在
[UIView animateWithDuration:0.25 animations:^{
[self.view layoutIfNeeded];
}];
之前执行:[self.view updateConstraintsIfNeeded];