在使用Masonry來(lái)做頁(yè)面布局的情況下添加動(dòng)畫效果

之前在寫代碼的時(shí)候發(fā)現(xiàn)使用了Masonry來(lái)做頁(yè)面布局的情況下,通過(guò)UIView的animateWithDuration 方法來(lái)添加動(dòng)畫是不會(huì)有效果的,那么應(yīng)該如何實(shí)現(xiàn)動(dòng)畫效果呢?

比如在點(diǎn)擊某個(gè)按鈕的時(shí)候需要更新約束,那么可以執(zhí)行下面的方法:

- (void)updateLayout {
    // 告訴當(dāng)前的頁(yè)面需要更新約束
    [self.view setNeedsUpdateConstraints];
    // 添加動(dòng)畫效果,3s執(zhí)行完畢
    [UIView animateWithDuration:3 animations:^{
        // 更新約束
        if (self.accountTextField.isShowKeyboard) {
            [self.titleImage mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(0.f);
            }];
            
            [self.accountTextField mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.view.mas_top).with.offset(SCREEN_SIZE_HEIGHT * 0.198);
            }];
        } else {
            CGFloat scale = iPad ? 1.5f : 1.f;
            [self.titleImage mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(65.f * scale);
            }];
            
            [self.accountTextField mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.view.mas_top).with.offset(SCREEN_SIZE_HEIGHT * 0.35);
            }];
        }
        // 告知發(fā)生變化的視圖的父視圖需要重新繪制
        [self.titleImage.superview layoutIfNeeded];
        [self.accountTextField.superview layoutIfNeeded];
    }];
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容