Masonry動畫更新約束

而知無涯發表於2018-03-06

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;
    }];
}
複製程式碼

相關文章