[英]Animate a view containing subviews with autolayout
This is the setup: 这是设置:
_vAbout
) _vAbout
) _ctrBottomAboutView
) _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...
我已经尝试了一切:添加和删除约束而不是修改常量值,在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 鉴于我们希望动画的视图和B的超级视图
layoutIfNeeded
message is the view that owns the constraint . layoutIfNeeded
消息的视图是拥有约束的视图,这一点非常重要。 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 NSLayoutAttributeWidth
和NSLayoutAttributeHeight
的情况下,约束的所有者实际上是A,但在所有其他情况下,拥有约束的视图是B HOWEVER 然而
[A layoutIfNeeded]
at any time on our code and it will work [A layoutIfNeeded]
,它会工作 viewDidLoad
we can call [A layoutIfNeeded]
and it will work viewDidLoad
上启动动画,我们可以调用[A layoutIfNeeded]
,它会工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.