概述
使用 UIView 起動畫求摇,通過 Masonry 設置的約束
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;
發(fā)現了兩個問題
- 并沒有動畫效果
- Masonry 報問題:約束有沖突
原因
經過觀察代碼發(fā)現
- UIView 在使用 Masonry 設置約束時窍荧,當起動畫時辉巡,需要在 animations Block 中調用
[self layoutIfNeeded]
刷新 superView - 在 UIView animation 中需要使用 Masonry
mas_remakeConstraints
更新約束,否則就會報 “約束沖突”的問題蕊退,因為 mas_makeConstraints 只負責新增約束郊楣,不能同時存在兩條針對于同一對象的約束
其他
mas_updateConstraints
與 mas_remakeConstraints
的區(qū)別
- update 會更新約束,如果出現有相同的約束方法瓤荔,只是值不同净蚤,則會直接使用新的約束
- remake 會清除掉之前的約束,重新設置約束