动画框架的UILabel平滑 [英] Animating Frame of UILabel smoothly
问题描述
我一直在试图找出一个体面的方式来平滑地动画帧大小变化在UILabel,没有奇怪的开始跳转重画。默认情况下发生的是,当我做这样的事情:
I've been trying to figure out a decent way to smoothly animate a frame size change on a UILabel, without a weird starting jump redraw. What happens by default is that when I do something like this:
// Assume myLabel frame starts as (0, 0, 100, 200)
[UIView beginAnimations:@"myAnim" context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:1.0];
myLabel.frame = CGRectMake(0.0, 0.0, 50, 100);
[UIView commitAnimations];
我得到一个流畅的动画与标签,但它是它需要重绘的图像层的目标大小的标签和streches的内容,以适应当前,然后动画到目的地rect。最终在文本显示中出现了一个非常奇怪的跳跃。以下是显示动画前外观,然后是动画开始后的两张图片:
I get a smooth animation with the label, however the way that it does it is that it takes the redrawn image layer for the destination size of the label and streches the content to fit the current then animates to the destination rect. This ends up with a very bizarre jump in the text display. Here are two images showing the pre-animation look, and then just after the animation starts:
前动画
Pre-Animation
动画后
Post-Animation
我试图只使用图层来动画,但我仍然得到相同的问题。
I have tried to use just the layer to animate this, but I still get the same issues.
所以问题是,如何避免这种情况?
So the question is, how can I avoid this?
感谢任何帮助,
Scott
Thanks for any help,
Scott
推荐答案
Hooray回答一个两年死的问题,但我发现了答案。在Interface Builder中或在代码中,更改标签的 contentMode
属性。您的似乎设置在 scaleToFill
;尝试左
或右
。
Hooray for answering a two-year dead question, but I found the answer. Either in Interface Builder or in code, change the contentMode
property of the label. Yours seems to be set on scaleToFill
; try left
or right
.
这篇关于动画框架的UILabel平滑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!