我有一个非常简单的应用程序.它包含一个红色视图和一个绿色标签.还有一个运行动画的按钮.我通过更改其宽度约束常量的值来为红色视图设置动画.
I have a very simple application. It contains a red view and a green label inside it. There is also a button that runs animation. I animate the red view by changing its width constraint constant's value.
[self.view layoutIfNeeded];
[UIView animateWithDuration:0.4 animations:^{
self.widthConstraint.constant = width;
[self.view layoutIfNeeded];
}];
红色视图按预期进行动画处理,但内部的绿色标签会立即改变其宽度.我玩了不同的动画标志,尝试了 SO 的几个技巧,但没有成功.
The red view animates as expected, but the green label inside changes its width instantly. I played with different animation flags, tried several tips from SO but did not bring it work.
请在此处找到来源.
TIA
看来我找到了问题的根源.约束不是问题,UILabel
是.
It seems like I've found the root of the problem. Constraints are not a trouble, UILabel
is.
如果您将我的项目中的 UILabel
替换为简单的 UIView
,它将按预期流畅地制作动画.这是 UILabel
内容动画的问题.您可以达到正确的动画行为集 label.contentMode = UIViewContentModeCenter
但它看起来很丑.
If you replace UILabel
in my project with simple UIView
it will animate smoothly as expected. It's a question of UILabel
content animation. You can reach correct animation behaviour set label.contentMode = UIViewContentModeCenter
but it looks ugly.
解决此问题的最佳方法 - 不要在动画期间尝试更改 UILabel
的大小.尝试发明一些其他行为.在我的情况下,我将 UILabel
的 alpha 更改为 0,并将 x 位置更改为大于容器视图的宽度.
The best way to solve this problem - not try to change size of UILabel
during animation. Try to invent some other behaviour. In my case I change UILabel
's alpha to 0 and x position to greater then container view's width.
请在这里找到更多关于 UILabel
动画的详细信息一个>.
Please find more details about UILabel
animating here.
这篇关于UILabel 在 UIView 内没有动画,使用了自动布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!