1.原约束
- (void)makeConstraints { [self.topContainer mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self); make.left.right.equalTo(self); make.height.mas_equalTo(kTopToolHeight); }]; [self.bottomContainer mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self); make.left.right.equalTo(self); make.height.mas_equalTo(kBottomToolHeight); }];}复制代码
2.动画更新约束
- (void)hidTool { [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; [UIView animateWithDuration:0.3 animations:^{ [self.topContainer mas_updateConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).with.offset(-kTopToolHeight); }]; [self.bottomContainer mas_updateConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self).with.offset(kBottomToolHeight); }]; [self layoutIfNeeded]; } completion:^(BOOL finished) { _isShowTool = NO; self.topContainer.hidden = YES; self.bottomContainer.hidden = YES; }];}复制代码