Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios: autolayout animation, how to prevent the subview be animated?

Tags:

ios

autolayout

We can change constant property of NSLayoutConstraint, and than use UIView animation block to make the change animated.

myLayoutConstraint.constant = 50;
[UIView animateWithDuration: .3 animations:^{
    [view layoutIfNeeded];
}];

However, the subviews of the view, which has layout constraints as their super view, will be animated! They will animate from original zero frame to the target frame of autolayout. How to solve this problem?

like image 307
Zhang Jiuzhou Avatar asked Mar 02 '15 09:03

Zhang Jiuzhou


1 Answers

This suggests that you have pending layout operations. Call layoutIfNeeded once before

myLayoutConstraint.constant = 50;
like image 115
rounak Avatar answered Oct 17 '22 00:10

rounak