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

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

    [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];

    }];

posted @ 2015-09-09 15:11  Milo_D  阅读(195)  评论(0编辑  收藏  举报