对约束的视图约束变化动画处理

有时候我们为了用户体验需要对约束的视图执行动画, 如下:

    [UIView animateWithDuration:0.3 animations:^{

        self.mButtomViewLayoutH.constant =  44;

        [self.mButtomView setNeedsLayout];

    }];

对self.mButtomView执行0.3秒的动画, 运行发现, 然并卵!  那怎么解决呢? 继续看...

原因在于你设置完视图后并没有通知父视图刷新约束. 所以你如下设置OK.

    [UIView animateWithDuration:0.3 animations:^{

        self.mButtomViewLayoutH.constant =  44;

        [self.mButtomView setNeedsLayout];

        [self.view layoutIfNeeded];

    }];

原文地址:https://www.cnblogs.com/Milo-CTO/p/4794769.html