在蘋果提供的動(dòng)畫方法block中直接使用Masonry更新視圖的約束婶博,并不能像使用frame那樣產(chǎn)生動(dòng)畫效果鸣剪。
代碼:
[UIView animateWithDuration:0.75 animations:^{
[self.redBtn mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.height.equalTo(@(150));
}];
}];
我們需要在更新約束之后還要調(diào)用該視圖父視圖的一個(gè)layoutIfNeeded方法才能產(chǎn)生動(dòng)畫效果薛耻。
代碼對(duì)比:
// 使用Masonry
[UIView animateWithDuration:0.75 animations:^{
[self.redBtn mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.height.equalTo(@(150));
}];
[self.redBtn.superview layoutIfNeeded];
}];
// 使用frame
[UIView animateWithDuration:0.75 animations:^{
self.yellowBtn.frame = CGRectMake(100, 300, 100, 100);
}];
效果對(duì)比:
動(dòng)畫.GIF
重要方法: [self.redBtn.superview layoutIfNeeded];
****本篇文章到這里就結(jié)束了篱竭,愿大家加班不多工資多昼接,男同胞都有女朋友构韵,女同胞都有男朋友莱衩。??***