使用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) {
}];
浙公网安备 33010602011771号