UILabel 的动画框架流畅 [英] Animating Frame of UILabel smoothly

查看:26
本文介绍了UILabel 的动画框架流畅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图找出一种体面的方法来平滑地为 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];  

我使用标签获得了流畅的动画,然而它的方式是将重绘的图像层用于标签的目标大小,然后拉伸内容以适应当前动画到目标矩形.这最终在文本显示中出现了一个非常奇怪的跳跃.这是两张显示动画前外观的图像,然后是动画开始后的样子:

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:

预动画

后期动画

我尝试只使用图层来制作动画,但我仍然遇到相同的问题.

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?

感谢您的帮助,
斯科特

Thanks for any help,
Scott

推荐答案

万岁,回答了一个两年的死问题,但我找到了答案.在 Interface Builder 或代码中,更改标签的 contentMode 属性.你的似乎是在 scaleToFill 上设置的;尝试 leftright.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆