使用Autolayout和约束后,用代码改变view的位置,并实现动画效果

例:将view上移

    //这种情况即使设置动画,还是没有动画效果
    [UIView animateWithDuration:0.3
                     animations:^{
                         
                        topLayout.constant = 0.0f;//需要移动到Y位置就设为Y
                         
                     } completion:^(BOOL finished) {
                     }];
    
    //解决方法
    [self.view layoutIfNeeded];
    [UIView animateWithDuration:0.3
                     animations:^{
                         
                         topLayout.constant = 0.0f;//需要移动到Y位置就设为Y
                         [self.view layoutIfNeeded];

                     } completion:^(BOOL finished) {
                     }];

 

posted on 2015-09-25 16:33  rgshio  阅读(161)  评论(0编辑  收藏  举报

导航