Animate a view containing subviews with autolayout
This is the setup:
_vAbout
) _ctrBottomAboutView
) I am using this code to animate:
_ctrBottomAboutView.constant = -100;
[UIView animateWithDuration:0.5 animations:^{
[_vAbout layoutIfNeeded];
}
My problem is: whenever the view has any subviews in it, the animation doesn't work . However, if the view has no children, the animation works correctly.
Do you have any idea of a solution? I have tried everything: adding and removing constraints instead of modificating the constant value, adding constraints to the subviews on Interface Builder...
After some experiments starting from the ground with an empty project, this is what I've found:
Given A the view we want to animate and B its superview
layoutIfNeeded
message is the view that owns the constraint . NSLayoutAttributeWidth
and NSLayoutAttributeHeight
the owner of the constraint is actually A, but in all the other cases, the view that owns the constraint is B HOWEVER
[A layoutIfNeeded]
at any time on our code and it will work viewDidLoad
we can call [A layoutIfNeeded]
and it will work 上一篇: 按月份MySQL表格分区
下一篇: 使用自动布局动画包含子视图的视图