里面的UILabel UIView的没有动画,使用自动版式 [英] UILabel does not animate inside UIView, autolayouts used
问题描述
我有一个非常简单的应用程序。它包含一个红色的观点和里面一个绿色标签。还存在运行动画的按钮。我通过动画改变其宽度约束常量的值红色的看法。
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];
}];
红色视图动画的预期,但绿色标签内立即改变其宽度。我打了不同的动画旗帜,从这么试了提示,但并没有带来它的工作。
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
的阿尔法为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
动画<更详细信息href=\"http://stackoverflow.com/questions/3298764/animating-uilabel-size-decrease/7923430#7923430\">here.
这篇关于里面的UILabel UIView的没有动画,使用自动版式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!