简体   繁体   中英

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

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?

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

myLayoutConstraint.constant = 50;

If the sub views have constraints that depend on the animated constraint then no this isn't possible.

What you can do though is make the constraints of the sub views independent of the animating constraint.

So, if you are animating the height of the preview then don't pin the sub views to the top AND bottom of their superview as this will make them change while it is animating. Only pin them to the top so that they "fall" off the bottom.

That way when the height is animated it will reveal the sub views in place without animating them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM